Page 1 of 1

monitor buttons during wait period

Posted: Wed May 31, 2006 10:30 pm
by Ron Zellner
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,

Posted: Thu Jun 01, 2006 12:10 am
by Ron Zellner
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.

Posted: Thu Jun 01, 2006 4:44 am
by Benedikt.Seidl
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.

Posted: Thu Jun 01, 2006 2:13 pm
by Ron Zellner
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

Posted: Thu Jun 01, 2006 6:49 pm
by Janschenkel
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.

Looks good

Posted: Fri Jun 09, 2006 1:12 pm
by Ron Zellner
OK, I'll give that a try. The "cancel sMessageID" is new to me, but the rest makes sense. Thanks.

Posted: Sun Jun 11, 2006 5:13 pm
by Mark
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