So I have code that runs on an event such as the user touching the screen. Multiple characters on screen at once, so when a touch event is registered, i determine which character is the target, then in a loop display the characters path and have the character move along that path. The problem is that i’m using timer.performWithDelay to run a method but if another character is targeted before the method is run the target is changed and the method runs with the NEW character parameter instead of the one that was initially called. anyone have a good workaround for this?
currentCharacter.totalTime=0;
for i, v in ipairs(currentCharacter.lines) do
local lineTimer = timer.performWithDelay(currentCharacter.totalTime, function()
if currentCharacter then
moveCharacterOld({phase="ended", x=v[1], y=v[2]}, currentCharacter);
end
end);
currentCharacter.totalTime = currentCharacter.totalTime+100;
table.insert(currentCharacter.lineTimers, lineTimer);
end
it’s the currentCharacter variable passed into moveCharacterOld that is not the right variable because it’s called after the currentCharacter.totalTime. [import]uid: 6317 topic_id: 1373 reply_id: 301373[/import]