But I don’t know the exact math equation without using a for loop to make for multiple rebirths. The price would go up depending on the actual rebirths.
E.G. ;
local rebirthsToDo = 20
local actualRebirths = 3
for i = 0, rebirthsToDo do
local price = (actualRebirths * 10000)
rebirth(Price) -- The actual rebirths would increase so, the price would go higher.
end
This would definitely work but I want to be able to do it with high numbers, like Millions and I can’t make a for loop with 1Mil.
Thank you!
Note : I may not be able to answer you rn, I’m going to sleep. I’ll see all messages tomorrow, thank you for your understanding!
All that code sample does is call the rebirth function with the argument 30,000 three times.
Could you elaborate on what the goal is? From my understanding, you want to convert some recursive mathematical function into a simple function, but it isn’t clear what the original recursive function is.
I wrote something similar for levels and experience. You can accomplish this without loops or recursive functions with arithmetic series and the quadratic formula.
I want to see the next rebirth price and add it to the current price, meaning that if I want to rebirth x10, I’ll calculate the price of first rebirth + price of second rebirth until 10, not one price x10.
My wording here is fairly confusing so I solved it for you. All you have to do is plug in the values to the script in my post above. start and increment would both be 10000. a and b defined below.
a1 = 10000
d = 10000
s(n) = n / 2 [2a1 + (n - 1) d]
s(n) = n / 2 [20000 + (n - 1) 10000]
s(n) = n / 2 [20000 + 10000n - 10000]
= 10000n + 5000n^2 - 5000n Divide all by two and multiply by n (n^2 in the case already multiplied by n)
= 5000n^2 + 5000n
Apply quadratic equation.
5000n^2 + 5000n - s(n) = 0
^^^^ ^^^^
a b
Let me re-explain. Okay, so, you have 1 rebirth. Each rebirth costs your actual rebirth * 10k in this case. So, if you had 2 rebirths, it would cost 20k, 3 rebirths-30k etc.
Now, what I want is to make massive rebirths directly, since rebirthing makes you lose everything you have. So like, I want into the process of finding price, if player chose to rebrith 5 times, it’ll count like that :
local RebirthsIHave = 1
local HowManyRebirths = 5
local price = 0
for i = 1, HowManyRebirths do
price = price + RebirthsIHave * 10000 -- The price will increase as we rebirth
RebirthsIHave = RebirthsIHave + 1
end
This would work but I don’t want to use a for loop, I want to get it done instantly, calculating the price only 1 time, meaning it will also calculate the price of the next rebirth until 5 in this case.
Sorry for all the edits… I didn’t understand what you were trying to do with the RebirthsIHave at first.
The formula is basically this. Will see about simplifying it.
local scale = 10000
local final_price = HowManyRebirths * (HowManyRebirths+1) * scale/2 + scale * ((RebirthsIHave-1)*(HowManyRebirths-1)+ RebirthsIHave-1)
So pretty much
First Rebirth is 10,000 = 10,000
Second Rebirth is 20,000 + First Rebirth = 30,000
Third Rebirth is 30,000 + second rebirth = 60,000
then 100,000
etc
This is really simple
local rebirthsToDo = 20
local startCost = 10000
local rebirthCost = 10000
for i=1, rebirthsToDo do
rebirthCost = rebirthCost + startCost*i
end
This add’s the player’s rebirth value by a thousand and then divides it by the amount of rebirths the player multiplied by 6. ( It doesn’t increase the rebirths, just an algorithm )
Well I highly doubt that anyone would do that many rebirths at once, however under that case, you could use that script to log the price of each rebirth
Create a table,
Put something like this into the loop
table.insert(rebirthCostTable, rebirthCost)
Then you could call it, otherwise I would look into the algorithms that others have posted here
Why are you guys making it this complicated, just use a exponential scale. Any equation of the form y=n^x will work fine, where n is the steepness of the function and x would be the amount of rebirths which you can track by your own means. Using a for loop for any sort of math that isn’t integration(but even integration in most cases) is a massive sign you’re doing something terribly wrong.