I have been making an upgrade simulator but im having issues making custom buy amount because my price formula is exponential
is there a way to calculate total price without using any loops
formula: 3 (base) x 2^current lv
I have been making an upgrade simulator but im having issues making custom buy amount because my price formula is exponential
is there a way to calculate total price without using any loops
formula: 3 (base) x 2^current lv
Can’t you just say this?
local level = --wherever your level is placed
local expNeeded = 3 * (2 ^ level.Value)
level means current level sorry if you got mistaken
Hello!
If I understand your question correctly, you want a sum of all prices, which all have the formula 3 * 2^lvl
like this?:
price = (3 * 2^1) + (3 * 2^2) + (3 * 2^3)...
local amount = 3
local totalPrice = 0
for level = 1, amount do
totalPrice += 3 * 2 ^ level
end
If yes, you can use the following formula n * (2 - 1 / (n / 6))
to get the sum of all prices, where n
is the highest price at the amount you want. For example, you can use it like this:
local amount = 3 -- the amount you want, 3 is a placeholder
local highestPrice = 3 * 2 ^ amount -- the highest, possible single cost
local totalPrice = highestPrice * (2 - 1 / (highestPrice / 6))
totalPrice
should now have the same results as the for loop above.
Hope I could help!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.