Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Please read the forum rules before posting.



Check if you are posting in the correct category.



The Off Topic section is not meant for discussing Cookie Clicker.

HELP: How to earn 1 resource per X amount of another resource

Korrupt86Korrupt86 Posts: 87Member ✭✭
edited December 2018 in Developer's Lounge
Does anyone know how to earn 1 resource per X amount of another resource for resurrect/prestige purposes.

****ANSWERED****

Building Icons:

Is it possible to change the default size of the icons? I think default is 48x48 but it is too small for my game, I want bigger like 128x128.

I would really appreciate it if anyone knows and is willing to teach me or even help code my game.
Post edited by Korrupt86 on

Comments

  • firefliesfireflies Posts: 56Member ✭✭
    a progress measure would be possible - having a resource set to 100 (%) and then decreasing by an amount, but to have it appear like a bar, you would need to have multiple variations being swapped out with a corresponding icon showing a bar in different states - if you showed 5% increments you would need 21 different images.

    As for icon sizes, that is controlled by CSS - as per the guide: "Note : sprites in Idle Game Maker tend to be 48 by 48 pixels. If you want to use a different image size, you may have to use CSS classes and custom styling."
  • Korrupt86Korrupt86 Posts: 87Member ✭✭
    fireflies said:

    As for icon sizes, that is controlled by CSS - as per the guide: "Note : sprites in Idle Game Maker tend to be 48 by 48 pixels. If you want to use a different image size, you may have to use CSS classes and custom styling."

    Can you please help me to make a new CSS class to make upgrade icons smaller then original size without affecting every other icon?

  • firefliesfireflies Posts: 56Member ✭✭
    You can use the line:

    class:cssClass

    to define a specific class - so in your upgrades section you could begin with:

    *TEMPLATE
    class:UpgradesSmall

    and then in your css file, I presume something along the lines of:

    div.UpgradesSmall { height:24px; width:24px; }

    I haven't played with using css files as yet so I cannot be 100% certain on the accuracy of the above - if you have any issues with it, let me know and I can test it further :)
  • Korrupt86Korrupt86 Posts: 87Member ✭✭
    edited December 2018
    fireflies said:

    You can use the line:

    class:cssClass

    to define a specific class - so in your upgrades section you could begin with:

    *TEMPLATE
    class:UpgradesSmall

    and then in your css file, I presume something along the lines of:

    div.UpgradesSmall { height:24px; width:24px; }

    I haven't played with using css files as yet so I cannot be 100% certain on the accuracy of the above - if you have any issues with it, let me know and I can test it further :)

    I tried this and it works in a sense. For example if I had a 50x50 image and reduced it to 25x25 using your method the image size stays at 50x50 but only a quarter of the image is touchable (Top left quarter) which is represented by the div.UpgradeSmall command. In essence it changes the size of the selectable area but not the image size itself.
  • Korrupt86Korrupt86 Posts: 87Member ✭✭
    I got it to work by using icon class:UpgradeSmall instead of class:UpgradeSmall in the game code (I did change the name of UpgradeSmall FYI, just using your name as reference)

    I have another issue in which you may know how to address.

    How do I get a building to give 1 of a resource when purchased. I have tried everything I know and i mainly used...

    on earn:yield 1 [Resource]

    This works for the first purchase only, as every purchase after that gives the same amount as the building you have purchased. For example,

    Building 1 after first purchase gives 1 [Resource] for a total of 1 [Resource]
    Building 2 after second purchase gives 2 [Resource] for a total of 3 [Resource]
    Building 3 after third purchase gives 3 [Resource] for a total of 6 [Resource]
    Building 4 after forth purchase gives 4 [Resource] for a total of 10 [Resource]
    Building 5 after fifth purchase gives 5 [Resource] for a total of 15 [Resource]

    As you can see after 5 purchases I have 15 [Resource] instead of desired 5.

    I have seen a code in another game which worked but I cant find the game or get the code to work for me. It looked similar to this...

    on earn:yield 1 > this [Resource]

    That may be typed incorrect but I have tried many other variations to no success.

    Any ideas?
  • firefliesfireflies Posts: 56Member ✭✭
    @Korrupt86 I found this to be a problematic issue when giving a set resource amount - there are a number of workarounds as follows:

    1) Yield a hidden upgrade, which in turn gives 1 resource and then loses itself - as the upgrade can only be gained once no matter how many yields are sent, it will only add a single resource on gain. This is the simplest and most effective method.

    2) More complex, but you could yield 1 divided by (total number of buildings) for the resource - that way if you have 1, it yields 1/1, if you have 2, it yields 2x 1/2, etc. so it would balance out

    3) If you want you can incorporate the problem into a feature by having the building yield another hidden building (which would naturally yield 1,2,3,4,etc buildings) and have it lose a building on tick - when it loses the final one, you add the resource - that way, each successive purchase will take longer to redeem the resource (diminishing returns penalty)
  • Korrupt86Korrupt86 Posts: 87Member ✭✭
    edited December 2018
    Ah ok so each time you buy a building it yields an upgrade instead of a resource. that upgrade then gives just 1 resource then locks itself ready to be yielded again.

    *EDIT*

    Thanks, the upgrade trick to give 1 resource works great.
    Post edited by Korrupt86 on
  • Korrupt86Korrupt86 Posts: 87Member ✭✭
    edited December 2018
    @fireflies Do you know how to earn 1 resource per X amount of another resource rather then do for example yield 1 gold, yield 0.1 diamonds.
    I need to know this for a resurrect/prestige/rebirth feature.

    Here is a look at my current design


    Post edited by Korrupt86 on
  • firefliesfireflies Posts: 56Member ✭✭
    again, you would probably want to use a hidden upgrade that has the on tick: event to yield the resource based on the values of the other...

    so:

    on tick:
    $gain = YourResource
    yield $gain YourOtherResource
    end


    Hope that helps :)
  • Korrupt86Korrupt86 Posts: 87Member ✭✭
    @fireflies i don't really understand that. do i put the on tick in an upgrade? if I put it in an upgrade how is the upgrade achieved and how does that tell Resource B that i only want 1 of it for every 100k Resource A
  • firefliesfireflies Posts: 56Member ✭✭
    The upgrade is achieved by adding a: yield upgradename

    You can add that from the start (you start with the hidden upgrade) or when another upgrade or building is purchased, or however it needs to begin.

    if you want 1 resource B per 100K resource A you would do something like:

    on tick:
    $gain = ResourceA
    $gain = ($gain / 100000)
    yield $gain resourceB
    end
  • Korrupt86Korrupt86 Posts: 87Member ✭✭
    edited January 1
    ok thanks ill give it a try.

    I did this as a hidden upgrade:

    *DiamondCounter
    on tick:
    $gain = TotalGold
    $gain = ($gain / 100000)
    yield $gain CurrentDiamonds
    end

    I created a building with (So as soon as you buy the first building and start making gold it should start to count)

    on earn:yield 1 DiamondCounter

    I have earned 300k gold so far and no Diamonds have appeared. Did I do something wrong?
    Post edited by Korrupt86 on
  • firefliesfireflies Posts: 56Member ✭✭
    is your 300k gold in a resource named "TotalGold" and are your Diamonds in a resource named CurrentDiamonds? would need to see your code if so, to see what the issue is
  • Korrupt86Korrupt86 Posts: 87Member ✭✭
    edited January 2
    yes. i have a resource and a stat for the resource. Gold gets spent so to make it give 1 diamond per 100k gold would never happen since you spend the gold, so i based it on the TotalGold stat so at every 100k total gold (Which you don't spend) it gives 1 Diamond which is coded as *CurrentDiamonds.

    Ill pm you the game code because i'm ready to release yet.
  • firefliesfireflies Posts: 56Member ✭✭
    @Korrupt86

    I looked at the code, and I can see what is happening...

    the on tick event doesn't like yielding a quantity from a variable (so a fixed number works) - it also doesn't want to yield another upgrade which is then lost, so any means of yielding an upgrade in a tick and then dropping it out again was doomed to failure.

    However as on tick is happy to yield a set amount of something that is not an upgrade, I ran a test in your code with a hidden resource.

    Your upgrade would now be:

    *DiamondCounter
    on tick:yield 1 test

    and the resource would then utilise an "on earn" which is much more flexible:

    *test
    on earn:
    $gain = TotalGold
    $gain = ($gain / 100000)
    yield $gain CurrentDiamonds
    lose this
    end


    The upgrade ensures that we only ever yield 1 test (resource), and the resource always resets itself.

    This resolves the issue of how to yield a variable amount per tick.

    However, from my understanding of your code - your intention is actually to have the "CurrentDiamonds" always reflect your TotalGold divided by 100k.... this would not be achieved with that fix, as each tick would add your TotalGold divided by 100k to the CurrentDiamonds total - a number that increases every second by 100,000th of your TotalGold.

    The solution is sadly much much much much simpler:

    *TotalGold
    name:Gold
    desc:This statistic keep track of how much Gold you have earned in total.
    show earned
    passive:CurrentDiamonds=(TotalGold/100000)

    The addition of the passive line in the TotalGold resource basically says, whatever TotalGold is, just set CurrentDiamonds to 100,000th of it - so when you hit 500k TotalGold, your CurrentDiamonds shows 5, etc.

    I hope that helps!
  • Korrupt86Korrupt86 Posts: 87Member ✭✭
    @fireflies thanks i will give it a go. I appreciate your time.
  • Korrupt86Korrupt86 Posts: 87Member ✭✭
    edited January 4
    just FYI my *DiamondCounter upgrade is not set to lose on earn so how is it being lost?

    Tested out your solution and it works sort of. Except when I have 15m total gold I have 300 CurrentDiamonds instead of the required 150 Current Diamonds. maybe i could change the /100000 to /50000?

    Image of what I mean...



    should have 377 diamonds not 750

    375 x 2 = 750 where it should be half of that
  • firefliesfireflies Posts: 56Member ✭✭
    If you want it to be just a direct /100,000 of your total gold at all times, go for the 2nd option - remove the upgrade (DiamondCounter), remove the resource, and just have the passive line in your TotalGold resource:

    *TotalGold
    name:Gold
    desc:This statistic keep track of how much Gold you have earned in total.
    show earned
    passive:CurrentDiamonds=(TotalGold/100000)

    That will make sure it always shows CurrentDiamonds as totalgold/100000 automatically
  • Korrupt86Korrupt86 Posts: 87Member ✭✭
    That works. Thanks.
Sign In or Register to comment.