why is the Stop button not working in 2nd stack?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

why is the Stop button not working in 2nd stack?

Post by keram » Fri Nov 22, 2013 3:44 am

Hi,

I made 2 stacks to test the Stop button for repeat loop. In one case it's working OK, but in the second it does not. Why is it so?

Here is the code and attached stacks.

working OK:
stack script:

Code: Select all

global startNextT

on startNext
   
   put empty into field "result"  
 
   repeat fld "reps" times         
      put "X" after fld "result"         
      wait 20 ticks      
   end repeat   
   
   send "startNext" to me in 120 ticks
   put the result into startNextT
   
end startNext
Start button:

Code: Select all

on mouseUp
   startNext
end mouseUp
Stop button:

Code: Select all

global startNextT
on mouseup
  cancel startNextT
end mouseup
---------------
Stop button not working:
stack script:

Code: Select all

global startNextT

on startNext
      repeat with countVar = 1 to 20        
      put countVar +1 into fld "counter"          
      wait 20 ticks      
   end repeat   
   
   send "startNext" to me in 120 ticks
   put the result into startNextT
   
end startNext
Start button:

Code: Select all

on mouseUp
   startNext
end mouseUp
Stop button:

Code: Select all

global startNextT
on mouseup
  cancel startNextT
end mouseup
Thanks for clarifying this.

keram
Attachments
stop button working and not.zip
(3.24 KiB) Downloaded 215 times
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

Robertel
Posts: 10
Joined: Sat Nov 02, 2013 6:21 am

Re: why is the Stop button not working in 2nd stack?

Post by Robertel » Fri Nov 22, 2013 6:55 am

Hi Keram,

I copied and pasted your scripts into the simplest stacks consistent with those scripts and the stop button worked in both for me. The second stack worked with no changes at all from what you posted. In the first stack I replaced

Code: Select all

repeat fld "reps" times 
with

Code: Select all

repeat for 5 times 
Robertel

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: why is the Stop button not working in 2nd stack?

Post by keram » Fri Nov 22, 2013 9:37 am

Thanks Robertel,

Yes, It is working as you said - it was my misunderstanding. I assumed that in the second one I could stop the current run (from 1-20) but the Stop button is stopping the next repeat of the '1-20 run'.

keram
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

AndyP
Posts: 634
Joined: Wed Aug 27, 2008 12:57 pm
Contact:

Re: why is the Stop button not working in 2nd stack?

Post by AndyP » Fri Nov 22, 2013 11:43 am

Hi Keram,

The problem is there is no time in the loop for your Stop button mouseUp message to get caught and actioned.

Try this:

Stack script
-------------------

global startNextT
global gButtonClicked // new global to get Stop button status
on startNext
repeat with countVar = 1 to 20
put countVar +1 into fld "counter"
wait 20 ticks with messages // added 'with messages' which allows time for message to get through
if gButtonClicked is "true" then // exit routine
exit to top // Halts the current handler and all pending handlers.
end if
end repeat
send "startNext" to me in 120 ticks
put the result into startNextT
end startNext


Start button
-----------------

global gButtonClicked
on mouseUp
put "false" into gButtonClicked
startNext
end mouseUP


Stop button
-----------------

global gButtonClicked
on mouseUp
put "true" into gButtonClicked
end mouseUp
Andy .... LC CLASSIC ROCKS!

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: why is the Stop button not working in 2nd stack?

Post by keram » Sat Nov 23, 2013 2:25 am

Hi Andy,

Thanks for your corrections - it worked OK.
I modified it slightly - want to resume from where it stopped and not from the beginning.
How to do that?

Script is here:

Stack script:
global startNextID,gButtonClicked,resume
on startNext
repeat with countVar = 0 to 10
put countVar +1 into fld "counter"
wait 20 ticks with messages // added 'with messages' which allows time for message to get through
if gButtonClicked is "true" then // exit routine
put fld "counter" into resume
put resume into fld "resume"

## something has to go in here but I don't know what :(

exit to top // Halts the current handler and all pending handlers.
end if
wait for 60 ticks
end repeat
end startNext

-----

Start button:
global startNextID,gButtonClicked,resume
on mouseUp
put "false" into gButtonClicked
startNext
end mouseUp

--------------

Stop button:
global gButtonClicked,resume
on mouseUp
put "true" into gButtonClicked
end mouseUp

-----------------

Also, I'm wondering, when I add a new variable like resume, do I have to add it as global and everywhere - not only on the stack but on all buttons as well?

keram
Attachments
stop-repeat-resume.zip
modified
(1.84 KiB) Downloaded 201 times
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

Post Reply