I am trying to make a control system with the classic 4 direction movement. where you push the up button and the character moves X distance up and stops. If I push the up button and then the right button before the first transition is complete I don’t want the second transition to interrupt the first, but I want it to go into a queue that will trigger the second transition once the first is complete.
I have thought out some code and figured this would work, which it mostly does, but the issue is that I cant seem to prevent new transitions from interrupting the one that is currently running.
If you guys could look at my code and help me out that would be great
ALSO: I think I would like the queue to have a limit of 2 in order to prevent a build up of a ton of moves that the player could input.
if someone could help me figure that out as well I would be very grateful.
moveQueue = {} local function moveHero(event) transition.moveTo( hero, moveQueue[1]) end local function removeFromQueue(event) table.remove( moveQueue, 1 ) if moveQueue ~= nil then moveHero() end end local function touchArrows(event) if event.target == leftArrow then table.insert( moveQueue, {x = -60, time = 1000, onComplete = removeFromQueue()} ) elseif event.target == rightArrow then table.insert( moveQueue, {x = +60, time = 1000, onComplete = removeFromQueue()} ) elseif event.target == upArrow then table.insert( moveQueue, {y = -60, time = 1000, onComplete = removeFromQueue()} ) elseif event.target == downArrow then table.insert( moveQueue, {y = +60, time = 1000, onComplete = removeFromQueue()} ) end end