Exit Repeat

Geoff Canyon gcanyon at inspiredlogic.com
Sun Mar 19 20:08:02 EST 2006


Close, but I don't think this will work. The exit to top in the  
escapeKey handler will exit that handler, not the  
handlerWithRepeatIMightWantToInterrupt. Instead, set a custom  
property in the escapeKey handler, then check that property in your  
handlerWithRepeatIMightWantToInterrupt handler and exit there if it  
is set. My previous example did something like this with a local  
variable, but a custom property would work as well.

gc

On Mar 19, 2006, at 2:51 PM, Mark Smith wrote:

> 'wait 0 ticks with messages' was the thing - thanks!
>
> So a general (stack-wide) approach might be to use a custom prop in  
> the stack:
>
> in a control, card or stack:
> on handlerWithRepeatIMightWantToInterrupt
>   set the canInterrupt of this stack to true
>   repeat forever
>     wait 0 ticks with messages
>     doRepeatStuff
>   end repeat
>   set the canInterrupt of this stack to false
>   otherStuff
> end handlerWithRepeatIMightWantToInterrupt
>
> then in the stack script
>
> on escapeKey
>   if the canInterrupt of me then
>     set the canInterrupt of me to false
>     exit to top
>   end if
> end escapeKey
>
>
> Mark
>
> On 19 Mar 2006, at 22:24, Geoff Canyon wrote:
>
>>
>> On Mar 19, 2006, at 12:04 PM, Mark Smith wrote:
>>
>>> Andre, the trouble is that in the case of interrupting a repeat  
>>> loop, you can't test for whether the escape key is down like you  
>>> can with control/option/command.
>>>
>>> So use control/option/command, of course :)
>>> But the escape key would be more natural...
>>
>> This works:
>>
>> local sGetOut
>>
>> on mouseUp
>>   put empty
>>   put false into sGetOut
>>   repeat 20000
>>     wait 0 ticks with messages
>>     if sGetOut then exit to top
>>   end repeat
>>   put "completed"
>> end mouseUp
>>
>> on escapeKey
>>   put true into sGetOut
>> end escapeKey
>>
>> Note that the escapeKey message is delivered to the focused  
>> control, so you can't put it in a button and expect it to work  
>> reliably. Put the above in the card script, then click anywhere in  
>> the card. Some time later "completed" will show in the message  
>> box. Then click the card again and then press the escape key. You  
>> won't get the "completed" text.
>>
>> gc
>> _______________________________________________
>> use-revolution mailing list
>> use-revolution at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your  
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-revolution
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>




More information about the Use-livecode mailing list