Thanks Peach,
But isn’t there still a little bit of wiggle room that might allow the function to run twice simultaneously, even with a flag? Let me take your code as an example. Let’s pretend that there are two events that cause myFunction() to be called. For argument sake, I’ll call them event A and event B. Here’s your code, just to reiterate:
[lua]local myFlag = false
local function myFunction(event)
if event.phase == “began” and myFlag == false then
myFlag = true
–Do stuff here
elseif event.phase == “ended” then
myFlag = false
end
end[/lua]
Now, let’s assume that A and B run very closely to the same time. So, event A runs line 1. Then event B runs line 1. Then event A runs line 3, then event B runs line 3. Then event A runs line 4, which is
[lua]if event.phase == “began” and myFlag == false then[/lua]
Then event B runs line 4. Both “threads” of code will see myFlag == false, and both will proceed to run the same code.
Is my scenario possible?
My work around is pretty tedious and would require a Lua stack implementation. It would work something like this:
[lua]local function queueMyFunction(argument)
– push argument on a queue
end
local function executeQueue()
– if there’s something on the queue, pop it off and do something
end
obj:addEventListener( “touch”, queueMyFunction)
Runtime:addEventListener(“enterFrame”,executeQueue)[/lua]
Thanks,
- Bret [import]uid: 168791 topic_id: 31694 reply_id: 126622[/import]