What am I doing wrong trying to update lists of coordinates at specific time interval ??
So I'm trying to make ghosting effect and in order to do that I need to store previous coordinates. I tried various ways to make timers I even copied one from tutorial on site tried to make use of Schedule function built in. tried after, every, do, sleep but that just frizzes the game like the whole game is sleeping not just function.
I'm calling this function from updateplayer witch is in turn called by update... Tell me what am I doing wrong
Here is function:
updateGhostPositions = function(obj, ghostTimer)
if ghostTimer != 0 then
ghostTimer -= 0.5 // do not tick lower than 0.5
else if newGhostTimer == 0 then
print(newGhostTimer)
obj.gx.insert(obj.x)
obj.gy.insert(obj.y)
if obj.gx.length > 21 then
obj.gx.pop()
obj.gy.pop()
end
ghostTimer = time
print(ghostTimer)
end
end
end
Solved if you are calling sleep from update function it will be called 60 times per second so the sleep will never end. You need to call it only once but in update function that is impossible at least to my knowledge. Advise do not use math for time measurement it will end up badly.
So what did I do:
initialized global variable to stop function from infinite loop and put my code in every x do statement
UGPstarted = 0
updateGhostPositions = function(obj, ghostTimer)
if UGPstarted == 1 then
return
end
if UGPstarted == 0 then
UGPstarted = 1
every 100 milliseconds do
obj.gx.insert(obj.x)
obj.gy.insert(obj.y)
if obj.gx.length > 5 then
obj.gx.pop()
obj.gy.pop()
end
end
end
end
Thanks for help and have a nice one. P.S. I really do hope that this will be helpful to someone.