QoL Update Multi Buy Button


Maybe not the most important feature for a game.
But I like "Multi Buy Buttons" and it was one of my open tasks for "Feed the Bunny".

My solution

Cycle through the different options and set the button text:


Function for calculation of the upgrade costs for a 'bulk' upgrade

I use a struct so I can return the values for the costs and the number of levels:


Calculate the current Basecost:


Finding out how many levels are needed to reach the multi buy goal:

a) for a set number of upgrade levels:


b) for fill level to 10 or 100


c) for MAX levels


Now that I know the number of upgrade levels I can calculate the sum of the upgrade costs for a 'bulk' upgrade:


Return the values (remember I used a struct to return 2 values):


The advantage of the struct for me is that I only have to call the function once for each upgradable item and then can use both needed values as often I want to in my processing.
Example:

And that's it. :-)


I look forward to comments on how other developers have solved this and hope I can help one or the other beginner with my solution.

Thank you for reading so far and apologizes for my English. I hope you understand anyway.

Leave a comment

Log in with itch.io to leave a comment.