I am trying to make an equation to simplify a process so I don’t have to do this:
if Unleashed == 1 then
StarsReleased = 10
elseif Unleashed == 2 then
StarsReleased = 20
elseif Unleashed == 3 then
StarsReleased = 30
elseif Unleashed == 4 then
StarsReleased = 40
elseif Unleashed == 5 then
StarsReleased = 50
elseif Unleashed == 6 then
StarsReleased = 65
elseif Unleashed == 7 then
StarsReleased = 80
end -- it goes on infinitely or until i get tired of typing it out
I’ve attempted to many different attempts at what the equation is. You can summarize my attempt as follows:
Yeah yeah that sounds like a whole not of nothing so let me explain it in english.
A player can unleash 10 boxes at a time. Every 5 times they unleash boxes, the amount of boxes they can unleash increases by 5. Meaning they unleash 10 boxes the first time, 10 boxes the second time, etc. up to 50 boxes. After they hit the 6th time of unleashing boxes, the amount increases by 15 this time. Meaning the 6th time they unleash, they will have released 65 boxes; 7th time 80 boxes etc…
I attempted equations for this but I’ve run out of hope and time so maybe someone here is a math genius and can help out.
Here was my failed equation, maybe it can help be a reference to the idea:
local Points = 16 -- failed... but close...
if Points%5==0 then
numericevaluation = 1
else
numericevaluation = (Points/5)-math.floor(Points/5)
end
(10*Points)+(5*((((math.ceil(Points/5)-1)-1)*5) + (((10*((numericevaluation)))/(math.ceil(Points/5)-1))*(math.ceil(Points/5)-1)))))
local points = 19 stars = ((10*points)+5*(5*(math.floor((points-1)/5))+(points - 6))) print(stars)
If we plug in 19, the answer should be 325 but it returned as 330.
If we plug 16 it should be 250 but we got 285. It seems just a little off.
If it is still difficult to understand I kind of converted it into a word problem:
A guy opens a pack of 10 rocks. For every 5 boxes he opens, the amount of rocks increase by 5. For example, the guy opens up 5 boxes for a total of 50 rocks, but the 6th box has 65 rocks. What equation can be used to summarize this problem? To further example for the sake of double checking, this would mean after opening 24 boxes, you would have 470 rocks.
I had some fun solving this problem, and made a function that returns the values as you need.
The function will start diverging from your if-then statements at Unleashed = 31, because you jumped from adding 25 to adding 40 rather than adding 30.
local function getReleasedStars(n)
local segment = math.floor(n/5)
local head = 12.5 * segment*segment + 37.5 * segment
local segmentRemainder = n - segment*5
local sum = segmentRemainder * (segment*5+10) + head
return sum
end
I might explain how I created this formula later on, but I don’t quite feel like doing so right now.
I finally came up with something that matches these if-statements.
local increaseEvery = 5
local increaseAmount = 5
function TranslateStarData(unleashed)
local starsReleased = 10 * unleashed
local increaseTimes = math.floor((unleashed - 1) / increaseEvery)
for i = 1, increaseTimes do
if (increaseTimes == 0) then break end
local remainder = math.min(math.max(unleashed - 5 * i, 0), increaseEvery)
for _ = 1, remainder do
if (remainder == 0) then break end
starsReleased = starsReleased + i * increaseAmount
end
end
return starsReleased
end
Thank you and everyone else for the attempts in assisting as well. I didn’t get to plug anything in with yours yet but I’ll test it out too just for the fun of it later.