monitor buttons during wait period

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Ron Zellner
Posts: 106
Joined: Wed May 31, 2006 9:56 pm
Location: College Station, Texas
Contact:

monitor buttons during wait period

Post by Ron Zellner » Wed May 31, 2006 10:30 pm

I'm setting up a sequence where an image is shown on the screen, and then it waits for a preset number of seconds.
The viewer is to click one of a set of buttons during this period and at the end of the wait time the button choice is recorded and a new sequence begun.
The problem is that using a repeat function or wait prevents Revolution from monitoring or responding to the button clicks.

I don't want to stop the wait period, just monitor the button activity during it.

I've done some complex things in Revolution but this baffles me as it doesn't seem like it should be a problem.
Am I looking at it the wrong way or something?
Thanks in advance,

Ron Zellner
Posts: 106
Joined: Wed May 31, 2006 9:56 pm
Location: College Station, Texas
Contact:

Post by Ron Zellner » Thu Jun 01, 2006 12:10 am

I solved this with a hint from Malte Brill:

on startTimer
if numberOfSecondswaited<30 then send startTimer to me in 1 second


I was simply calling the handler from within itself (as in Javascript), rather than using 'send'. The 'send' fixed it.

Thanks Malte.

Benedikt.Seidl
Posts: 9
Joined: Sat Apr 08, 2006 3:54 pm

Post by Benedikt.Seidl » Thu Jun 01, 2006 4:44 am

you can also use

Code: Select all

on nextimage
  ## here you can display your new pic
  send "nextimage" to me in 5 sec
end nextimage
the clicked btn can be recorded by a global or a costum property. for example (code of a btn):

Code: Select all

global clickedbtn
on mouseup
  if the clickedbtn is empty then ## an other btn has been klicked alreadey
    ## you have to empty this global in your nextimage handler
    put the name of me into clickedbtn
  else
    beep
  end if
end mouseup
and once again the nextimage code:

Code: Select all

global clickedbtn
on nextimage
  ## here you can display your new pic
  put clickedbtn & cr before fld "btnlist"
  put empty into clickedbtn ## 
  send "nextimage" to me in 5 sec
end nextimage
hmmmm,.. i hope it is useful for you,..

SEIDL.

Ron Zellner
Posts: 106
Joined: Wed May 31, 2006 9:56 pm
Location: College Station, Texas
Contact:

Post by Ron Zellner » Thu Jun 01, 2006 2:13 pm

This is the basic function that I am using; the viewer makes choices during the 10 second interval by clicking buttons.
The problem was being able to monitor the buttons while this was running.
The 'send CheckIt to me' was the means of repeating the sequence, but the critical factor is the 'in 1 second'.
I did not have that part there before so there was no time opening to watch the buttons. Now it watches during each 1 second interval and works fine.

Code: Select all

on CheckIt2
  Global start, ChoiceS
  put the seconds - start
  if  the seconds - start < 10 then send CheckIt2 to me in 1 second
  else     
    put ChoiceS & return after field "choices"   -- records viewer's choices  
  end if
end CheckIt2

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Location: Aalst, Belgium
Contact:

Post by Janschenkel » Thu Jun 01, 2006 6:49 pm

Alternately, you can store the messageID that is put into 'the result' when you use a 'send in time' construct, and 'cancel' that when someone picks a choice.

So you would have something like this in the card script.

Code: Select all

local sMessageID

on StartQuestion
  -- setup everything for the next question
  -- ...
  -- now fire off the timer and save the messageID
  send "FinishWithoutAnswer" to me in 10 seconds
  put the result into sMessageID
end StartQuestion

on FinishWithoutAnswer
  -- clean up the messageID, just to be on the safe side
  put empty into sMessageID
  -- show the user some 'out of time' message
  -- ...
end FinishWithoutAnswer

on FinishWithAnswer
  -- make sure we don't see the 'out of time' message
  if sMessagerID is not empty then
    cancel sMessageID
    put empty into sMessageID
  end if
  -- show the user if their choice was right
  -- ...
end FinishWithAnswer
Then, when the user makes a choice (presumably by clicking a button or an image), make sure its script calls the 'FinishWithAnswer' handler to prevent the 'out of time' scenario.

With such a system, your app stays responsive -- you can add a second timer construct to update a field with a text like 'N seconds left', retain its messageID in another script local variable, and cancel that from the FinishWithAnswer handler in one go.

Hope this helped,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

Ron Zellner
Posts: 106
Joined: Wed May 31, 2006 9:56 pm
Location: College Station, Texas
Contact:

Looks good

Post by Ron Zellner » Fri Jun 09, 2006 1:12 pm

OK, I'll give that a try. The "cancel sMessageID" is new to me, but the rest makes sense. Thanks.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Sun Jun 11, 2006 5:13 pm

For more information about the cancel command, you might want to read the docs for cancel and pendingMessages.

The id number used by cancel is the first item of a line of the pendingMessages.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply

Return to “Talking LiveCode”