Interrupting "Wait"

Alex Tweedly alex at tweedly.net
Mon Dec 31 10:21:31 EST 2018


In essence, you want something like the following:

(this assumes a capital Q typed to the card will quit the display. It 
could easily be changed to clicking a button - so long as the mouseUp 
handler would set the script-local when appropriate).

local sStopRequested

command playShow
    local tPhotos
    put FALSE into sStopRequested
    put randomPhotoList() into tPhotos
    repeat for each line L in tPhotos
       dispatch "loadImage" with L
       wait 5 seconds with messages
       if sStopRequested then exit repeat
    end repeat
    dispatch "loadImage" with "defaultMainImage"
end playShow

on rawKeyUp pKey
    if pKey = "Q" then
       put TRUE into sStopRequested
    else
       pass rawKeyUp
    end if
end rawKeyUp


NB this has the limitation that there will be a delay of up to 5 seconds 
after the user types the 'Q" before it takes effect. If you need to 
avoid that and get more immediate response, then you could replace
       wait 5 seconds with messages
       if sStopRequested then exit repeat
with
       repeat 5 times
          if sStopRequested then exit repeat
          wait 1 second with messages
       end repeat -- for the number of seconds
       if sStopRequested then exit repeat

or similar (or put that logic into a handler).

And as a bonus, you could easily add more typing options ...
    Q for quite the slideshow
    SPACE for next photo immediately
    arrowkey for next/previous, erc

Alex.

On 31/12/2018 15:02, Sannyasin Brahmanathaswami via use-livecode wrote:
> global sConfigA,sHomeImageFile,sNarrativePlayFlag,sMainImage,sNextImage
>
> command startNarrative
>     put path_Assets()& "img/siva-darshan/who-is-siva_1200x800.jpg" into sHomeImageFile
>     put "true" into sNarrativePlayFlag
>     put the long id of img "homeStoryMainImage" of me into sMainImage
>     put randomDietyPhotos() into tPhotoList
>     repeat for each line pPath in tPhotoList
>        if sNarrativePlayFlag then
>           dispatch "loadNewImage" to me with pPath
>           --send "loadNewImage pPath" to me
>           wait for 1 seconds
>        else
>           put pendingMessages()
>           --loadNewImage sHomeImageFile
>           -- screen with visual effect "dissolve"
>           exit repeat
>        end if
>     end repeat
> end startNarrative
>
> command loadNewImage pPath
>     hide sMainImage with effect "dissolve" to black
>     lock screen
>     set the filename of sMainImage to pPath
>     setRectOfCurrentGrc sMainImage
>     put the loc of this card into tLoc
>     subtract 27 from item 2 of tLoc
>     resizeToHeight sMainImage,(the height of this card -58)
>     set the loc sMainImage to tLoc
>     unlock screen --with visual effect "dissolve"
>     show sMainImage with visual effect "dissolve"
> end loadNewImage
>
> command stopShow
>     loadNewImage sHomeImageFile
>     put "false" into sNarrativePlayFlag
> end stopShow





More information about the Use-livecode mailing list