I'm having a hell of a problem with onComplete functions and program flow

How can I complete the startAnimNode() / contAnimNode() / finishAnimNode() sequence in the ‘for nodeIndex = 1, 3 do’ loop for all of the three nodes before the program continues to run and calls the task3() - task6(), task2() functions?

local animInProgress = false  
  
local theNodes = {  
 node1,  
 node2,  
 node3  
}  
local theNodesIndex  
  
function finishAnimNode(event)  
 -- finish up  
 animInProgress = false  
end  
  
function contAnimNode(event)  
 -- fade out  
 transition.to( theNodes[theNodesIndex], {time=500, alpha=1.0, onComplete= finishAnimNode})  
end  
function startAnimNode(index)  
 -- fade out  
 animInProgress = true  
  
 transition.to( theNodes[theNodesIndex], {time=500, alpha=0.25, onComplete=contAnimNode})  
end  
  
function checkNodes()  
 task1()  
  
 for nodeIndex = 1, 3 do   
 task2()  
  
 theNodesIndex = nodeIndex  
 startAnimNode()  
  
 task3()  
 task4()  
 end  
  
 task5()  
 task6()  
end  

I created a flag called ‘animInProgress’ but no matter how I use it the program will continue to run and end with the possibility of the other tasks either being called when they shouldn’t, or NOT being called when they should.
[import]uid: 295 topic_id: 1740 reply_id: 301740[/import]

I’m confused about what you want to do. Do you want task3() to run only after finishAnimNode() completes? [import]uid: 54 topic_id: 1740 reply_id: 5179[/import]

Yes. [import]uid: 295 topic_id: 1740 reply_id: 5196[/import]

Do you want something like this?

[code]

local animInProgress = false

local theNodes = {
node1,
node2,
node3
}
local theNodesIndex

function finishAnimNode(event)
– finish up
animInProgress = false

– do these tasks after all transitions are completed, for each node
task3()
task4()

if theNodesIndex == 3 then
– do these tasks after all nodes are completed
task5()
task6()
end
end

function contAnimNode(event)
– fade out
transition.to( theNodes[theNodesIndex], {time=500, alpha=1.0, onComplete= finishAnimNode})
end

function startAnimNode(index)
– fade out
animInProgress = true

transition.to( theNodes[theNodesIndex], {time=500, alpha=0.25, onComplete=contAnimNode})
end

function checkNodes()

task1()

for nodeIndex = 1, 3 do
task2()

theNodesIndex = nodeIndex
startAnimNode()
end
end
[/code] [import]uid: 54 topic_id: 1740 reply_id: 5204[/import]

That looks like it’ll do the trick. Thanks. I’m still getting used to this event-driven programming. When I used to program, a program would take over the computer and the OS was preemptive multitasking (Amiga) or cooperative multitasking (Mac System 6). And callbacks were not used (or I didn’t understand them well although I did make use of them writing printer drivers for SUN Solaris). [import]uid: 295 topic_id: 1740 reply_id: 5208[/import]