In this post http://www.coronalabs.com/blog/2012/04/24/working-with-time-delays-and-counting/ it is well explained how to use the performWithDelay for a function with arguments:
timer.performWithDelay( 1000, function()
hello_world( “first”, “second” )
end, 1 )
However what if I have a recursive function and I want to get a value back?
This is the concrete example:
function minmax (args)
…
returnValue = minmax(newagrs)
end
Now I use this function to calculate a tree of possible moves for the AI. However this takes a bunch of seconds and my spinning wheel widget is frozen with a very bad effect…
So my idea was to use the timer.performWithDelay every time I want to call again the minmax function just to give a couple of millisends to the system to let the spinning wheel to actualy spin…
But I how can I retrive the returnValue ?
if I do
timer.performWithDelay( 1000, function()
returnValue = minmax (newargs)
end, 1 )
the returnValue variable is not in scope with the calling function…
As alternative I am ok to have any other way to force the wheel spinning …
Thank you,
Ema