increase a variable value based on score increment

Hello Again! 

im running into a wall but i believe its something very simple. 

i have a variable fallRate

fallRate = 100

i want to increase this fallrate by say 10 for every three points scored 

i can do this by of course writing out tons of functions  similar to this 

local function increaseFallRate() if (score == 3) then fallRate = fallRate + 2000 end

but im sure there is a much easier way to do this rather than writing out 30 functions.

i tried 

local function increaseFallRate() if (score = score + 3) then fallRate = fallRate + 2000 end

but this produced no results at all 

i set the fallRate to 2000 just so there is a dramatic change and i could see it immediately within the simulator.  

fallRate if the variable i use to set the linear Velocity of spawned objects. 

thanks in advance 

There’s any number of ways to handle it, this is one:

[lua]

local startingFallRate = 100

local fallRateIncreasePerInterval = 10

local increaseFallRateInterval = 3

local score = 0

local recalculateFallRate = function ()

 fallRate = startingFallRate + (math.round(score / increaseFallRateInterval)) * fallRateIncreasePerInterval

end

local changeScore = function (amount)

  score = score + amount

  recalculateFallRate()

end

changeScore(3)  – call this whenever points are scored with the value to add

[/lua]

this worked well, i had to set the increaseFallRateInterval  to 6 that way every 3 points it increases the fallRate by the interval 100

unless i did something wrong  but it for sure worked out

Thank you

Cool - I made a mistake in not declaring fallRate at the top - it’s currently a global variable. And you should probably use math.floor instead of math.round, otherwise a score of 5 will equal two intervals. 

changing it to math.floor made it work according to the actual score interval instead of half. 

now that i read the documentation on math.round and math.floor it makes more sense.