Reputation: 851
How to increase movementSpeed
by decreasing star1.movementSpeed = 10000;
with -1 every
10 seconds.
i have tried this, but can't figure out what i am doing wrong
function initStar()
local star1 = {}
star1.imgpath = "Star1.png"; --Set Image Path for Star
star1.movementSpeed = 10000; --Determines the movement speed of star
table.insert(starTable, star1); --Insert Star into starTable
end --END initStar()
local function star1incr() -- increments Speed value every time it is called
movementSpeed = movementSpeed - 1
star1.movementSpeed = "movementSpeed: " .. movementSpeed
end
timer.performWithDelay(10000, star1incr, 0)
Upvotes: 0
Views: 417
Reputation: 851
Fixed by using
local function star1incr()
starTable[1].movementSpeed = starTable[1].movementSpeed - 1
print( "- 1" )
end
Upvotes: 2
Reputation: 26774
You need to have a variable you can share between initStar()
and star1incr()
(btw, "increment movementSpeed
by decreasing ...movementSpeed
doesn't sound right); something like this may work:
local star1 = {}
function initStar()
star1.imgpath = "Star1.png" --Set Image Path for Star
star1.movementSpeed = 10000 --Determines the movement speed of star
end --END initStar()
local function star1incr()
star1.movementSpeed = star1.movementSpeed - 1
end
timer.performWithDelay(10000, star1incr, 0)
star1
variable will be shared between initStar
and star1incr
functions (in Lua terminology it's called an upvalue).
Upvotes: 1