Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Making a Buy Max Button for My Clicker Game
- hueychen
-
Scratcher
35 posts
Making a Buy Max Button for My Clicker Game
So I'm making https://scratch.mit.edu/projects/778354226/ which is a clicker game and I want to make a buy max button. A buy max button is used to buy the most amount of upgrades without having a negative amount of money. I have found this but I don't really know if I turned this into Scratch code correctly.
These are the equations I know that I need:
b = 0.02;
r = 1.5;
k = Upgrades;
c = money;
n=floor(log(c(r−1)b(rk)+1)/log(r));
cost=b∗rk(rn−1)r−1;
However I'm not sure if I can accurately make the equations code. Any idea of doing this and how to implement it into my game?
These are the equations I know that I need:
b = 0.02;
r = 1.5;
k = Upgrades;
c = money;
n=floor(log(c(r−1)b(rk)+1)/log(r));
cost=b∗rk(rn−1)r−1;
However I'm not sure if I can accurately make the equations code. Any idea of doing this and how to implement it into my game?
- mchen2010
-
Scratcher
40 posts
Making a Buy Max Button for My Clicker Game
I'm sorry, but the math you found is likely incorrect, the /log()/ function is not used to calculate the max amount.
To make a real max button, this code should be used:
(
1. The easy way
2. The math way
both work.
To make a real max button, this code should be used:
(
(needed_amount)is a negative number, denoting how much it will take away.)
1. The easy way
repeat until <(coins) < [0]>
change [coins v] by (needed_amount) //subtract the correct amount of coins for purchase
change [purchased v] by (1) //change amount of purchaed items
end
change [coins v] by ((-1) * (needed_amount)) //the loop will overdo it
change [purchased v] by (-1)
2. The math way
set [coins v] to ((coins) mod ((-1) * (needed_amount))) //the ()mod() function calculates the remainder of a division, e.g. (5)mod(2) = 1.
set [purchased v] to ([floor v] of ((coins) / ((-1) * (needed_amount)))) //This calculates the amount of times you can have needed amount, and makes it a whole number
both work.
Last edited by mchen2010 (Dec. 29, 2022 06:14:06)
- mchen2010
-
Scratcher
40 posts
Making a Buy Max Button for My Clicker Game
The needed_amount varable is the cost varable. It needs to be a negative number.
- hueychen
-
Scratcher
35 posts
Making a Buy Max Button for My Clicker Game
Can you show this in a project?
- mchen2010
-
Scratcher
40 posts
Making a Buy Max Button for My Clicker Game
I *don't* really want to make a project right now… You should be able to smoothly integrate it into your program, I think.
wait - Does the price of the item increase every buy? My calculations only account for a linear growth, not a exponential.
wait - Does the price of the item increase every buy? My calculations only account for a linear growth, not a exponential.
- SavetheAtlantic
-
Scratcher
1000+ posts
Making a Buy Max Button for My Clicker Game
([floor v] of (([log v] of ((((c ::grey) * ((r ::grey) - (1))) * ((b ::grey) * ((r ::grey) * (k ::grey)))) + (1))) / ([log v] of (r ::grey))))
- hueychen
-
Scratcher
35 posts
Making a Buy Max Button for My Clicker Game
I *don't* really want to make a project right now… You should be able to smoothly integrate it into your program, I think.Yes, it grows exponentially by 1.5 for the cost. Also the value of the click grows exponentially by 1.1.
wait - Does the price of the item increase every buy? My calculations only account for a linear growth, not a exponential.
- casp803e
-
Scratcher
2 posts
Making a Buy Max Button for My Clicker Game
Thanks this was really helpful
- Discussion Forums
- » Help with Scripts
-
» Making a Buy Max Button for My Clicker Game