Hi,
In developing of my App, i have two problem caused by the fact that I do not understand how to stop a loop with an event.
I have written the following code to replicate this problem.
In my App there is a complex model that takes up to two minutes of time to calculate the solution.
I would like to have the possibility to show the time that pass during the calculation and to stop or start again the calculation through the click on two differents buttons (in the code are two circles for simplicity)
How is visible from the following code, I can view the time passing and stop the loop only when the same loop is finished.
Someone has already had this issue?
Sorry for my english.
Thanks for the tips that will come
regards,
Gianluca
local calculation\_progress=true local messagge\_obj=display.newText("Start Calculation",display.contentCenterX-200, display.contentCenterY-200, native.systemFont, 40) messagge\_obj:setTextColor( 255, 255, 255 ) --- here there is a simple function, but in my App is a complex loop that works until 2 minutes local function loop\_fun() messagge\_obj.text="Calculation started" local max\_comps=1000000 for i=1,max\_comps do if calculation\_progress==true then local messagge\_loop=tostring(i) --- here is a simple model print(messagge\_loop) else break end end messagge\_obj.text="Calculation done" end --- setting of the timer local test\_time\_label = display.newText("Time:", display.contentCenterX-125, display.contentCenterY-50, native.systemFont, 40 ) local test\_time = display.newText("", display.contentCenterX-20, display.contentCenterY-10, native.systemFont, 40 ) local function refresh\_time() local currentTime = os.date("\*t") test\_time.text=os.time( t ) --currentTime end Runtime:addEventListener("enterFrame", refresh\_time) --- setting of play and stop button local function play\_calc() calculation\_progress=true loop\_fun() print("calculation\_progress",calculation\_progress) end local function stop\_calc() calculation\_progress=false print("calculation\_progress",calculation\_progress) end local myButton\_calc\_play = display.newCircle(display.contentCenterX+60,display.contentCenterY+200,60) local test\_play = display.newText("Play", display.contentCenterX+10,display.contentCenterY+180, native.systemFont, 45 ) test\_play:setTextColor(0) test\_play:addEventListener("tap", play\_calc) local myButton\_calc\_stop = display.newCircle(display.contentCenterX-100,display.contentCenterY+200,60) local test\_stop = display.newText("Stop", display.contentCenterX-145,display.contentCenterY+180, native.systemFont, 45 ) test\_stop:setTextColor(0) test\_stop:addEventListener("tap", stop\_calc)