How do I prevent production of resource from exceeding storage cap (Solved!)?

0 favourites
  • 9 posts
From the Asset Store
Basic Plugins for Firebase Authentication, Realtime-Database, Firestore, Cloud Storage
  • Hey everyone.

    As the title suggests, the game produces a resource every 2 seconds (set low threshold to aid in trouble-shooting). The quantity of that resource is included in the global variable "Total_Dry_RSS". Another global variable "Total_Dry_Storage_Capacity" is the max amount of all the dry resources that can be stored.

    However, if the storage capacity is 100 and the total dry rss is 80, in 2 seconds, the resource goes up 30 or whatever and shows as 110. How can I get the resource to increase but not past the cap?

    Thank you!

    If you're around winstreak, I would appreciate it.

    Tagged:

  • When adding resources,

    Set resources to min(resources+added resources,maximumresources)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • When adding resources,

    Set resources to min(resources+added resources,maximumresources)

    Freaking GENIUS! Thank you very much.

  • Follow-up question. When there are two or more resources (apples/oranges/limes), could I use the same code but in a different way? By adding a second resource, the total dry storage goes over the capacity again.

  • In that case, you'll actually want the space remaining, which is totalspace-(a+b+c), where a, b, and c are your resources.

    When adding resources, you'll add the full amount of new resources, or the total remaining space, whichever is lesser.

    So a+min(newa,totalspace-(a+b+c))

  • Right! Brilliant work. Testing now.

  • So a+min(newa,totalspace-(a+b+c))

    resourceA+min(resourceA,totalspace-(resourceA+B+C))

    I can't figure out what value "newA" is. Sorry man.

  • NewA is the amount of A you're trying to add.

  • NewA is the amount of A you're trying to add.

    That's it! Not sure why I made it so difficult in my head but I got it now. Thanks again for the answer and your patience.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)