Page 1 of 1
help with cancelling and reinstating send command....
Posted: Tue Jan 13, 2015 2:27 am
by kjon2010
Hi All
I have a program where people are under a time constraint to answer a question. Once the question is displayed they have 5.5 seconds to respond (a response is a keypress), after 3 seconds they get a warning msg saying that time is almost up, and after a further 2.5 seconds they are timeout, that is the question is removed from the screen and replaced by the next one.
The warning msg and timeout are coded by sending a series of handlers which check whether a key has been pressed. On the keydown the "check" handler is sent after 3 seconds, on "check" if a key hasn't been pressed then the "warningmsg" handler is sent, this displays the warning msg and in 2.5 seconds sends "check2" to the card. Check2 sees whether a key has been pressed and if not then it sends the "timeout" handler to the card, this removes the question and sets up the next one.
My problem is that I can't appear to stop this loop once it has begun, i.e. if someone doesn't respond initially, gets the warning msg and then responds, when the next question is displayed the program lets them take as much time as it wants, i.e. the loop is not restarted, it appears that because the "check" command was sent once it doesn't do it again (however once a key is pressed on this second question the third one does have the timeout loop working...).
Secondly if someone responds quickly before getting any warning msg, on the next trial the warning appears almost instantly and the timeout follows, it seems that the send command is not being reset/cancelled, i.e. from the first keypress it is still counting down 3 seconds and even if someone has responded it still starts the loop.
At the beginning of on keypress I have the following code which I hoped would interupt the loop:
repeat for each line aLine in the pendingMessages
if aLine contains "check" then
cancel item 1 of aLine
end if
end repeat
repeat for each line aLine in the pendingMessages
if aLine contains "check2" then
cancel item 1 of aLine
end if
end repeat
repeat for each line aLine in the pendingMessages
if aLine contains "warningmsg" then
cancel item 1 of aLine
end if
end repeat
repeat for each line aLine in the pendingMessages
if aLine contains "timeout" then
cancel item 1 of aLine
end if
end repeat
Any help on how to cancel the send messages, or the handlers would be greatly appreciated!!
Cheers,
Kelly
Re: help with cancelling and reinstating send command....
Posted: Tue Jan 13, 2015 2:59 am
by dunbarx
Hi.
You should be able to do this all in your handlers. Not that canceling pendingMessages is wrong. But without seeing your code there is no way to start to help.
Craig Newman
Re: help with cancelling and reinstating send command....
Posted: Tue Jan 13, 2015 5:01 am
by kjon2010
HI Craig
thanks for the quick reply, my code is below (apologies for how convoluted it is.....)
Code: Select all
global condition, btrial, gfilename, path2, order, startmilliseconds, endmilliseconds, trial, timingcondition, buttonresponding, RTMS, endticks, startticks, startreadingtimeticks, endreadingtimeticks, startreadingms, endreadingms, conclusionenabled, ReadingTimeMSaccordingtoticks, ReadingTimeMS, keypress, warningmsggiven
on preopencard
set the itemdelimiter to tab
put "0" into fld "keypress"
put " " into fld "timer"
put "no" into fld "warningmsggiven"
put 1 into btrial
----------------------------------------------
end preopencard
on opencard
set the itemdelimiter to tab
wait 2 seconds
show fld "instructions"
wait 4 seconds
show btn "start"
end opencard
on keydown thekey
if keypress = "responseneeded" then
if thekey = " " then
exit keydown
end if
else
repeat for each line aLine in the pendingMessages
if aLine contains "check" then
cancel item 1 of aLine
end if
end repeat
repeat for each line aLine in the pendingMessages
if aLine contains "check2" then
cancel item 1 of aLine
end if
end repeat
repeat for each line aLine in the pendingMessages
if aLine contains "warningmsg" then
cancel item 1 of aLine
end if
end repeat
repeat for each line aLine in the pendingMessages
if aLine contains "timeout" then
cancel item 1 of aLine
end if
end repeat
repeat for each line aLine in the pendingMessages
if aLine contains "timer" then
cancel item 1 of aLine
end if
end repeat
end if
-------------
if thekey = "z" then
if buttonresponding = "disabled" then
exit keydown
end if
get flushEvents("all")
put empty into fld "test"
set the itemdelimiter to tab
put "1" into fld "keypress"
put "disabled" into buttonresponding
put "questiontime" into keypress
put " " into fld "timer"
put "no" into fld "warningmsggiven"
hide fld "timer"
add 1 to btrial
switch
case btrial = 25
hide fld ("instructions"&condition)
hide fld "warning"
hide fld "conclusion"
hide image "line"
hide fld "premise2"
hide fld "premise1"
hide fld "Iremind"
hide fld "Dremind"
wait 1 seconds
show fld "end"
show btn "end"
break
case btrial <25
repeat with a = 1 to 2
hide fld ("premise"&a)
end repeat
hide fld "conclusion"
hide image "line"
hide fld "Iremind"
hide fld "Dremind"
wait 1 seconds
put item 4 of line btrial of fld "beliefstatements" into fld "premise1"
put item 5 of line btrial of fld "beliefstatements" into fld "premise2"
put item 6 of line btrial of fld "beliefstatements" into fld "conclusion"
show fld "premise1"
show fld "premise2"
show image "line"
show fld "conclusion"
put "0" into fld "keypress"
put "responseneeded" into keypress
put "enabled" into buttonresponding
send check to this card in 3 seconds
break
put flushevents ("keydown") into trash
end switch
end if
if thekey = "/" then
if buttonresponding = "disabled" then
exit keydown
end if
get flushEvents("all")
set the itemdelimiter to tab
put "1" into fld "keypress"
put "disabled" into buttonresponding
put " " into fld "timer"
put "questiontime" into keypress
put "no" into fld "warningmsggiven"
hide fld "timer"
add 1 to btrial
switch
case btrial = 25
hide fld ("instructions"&condition)
hide fld "warning"
hide fld "conclusion"
hide image "line"
hide fld "premise2"
hide fld "premise1"
hide fld "Iremind"
hide fld "Dremind"
wait 1 seconds
show fld "end"
show btn "end"
break
case btrial <25
repeat with a = 1 to 2
hide fld ("premise"&a)
end repeat
hide fld "conclusion"
hide image "line"
hide fld "Iremind"
hide fld "Dremind"
wait 1 seconds --increase later
put item 4 of line btrial of fld "beliefstatements" into fld "premise1"
put item 5 of line btrial of fld "beliefstatements" into fld "premise2"
put item 6 of line btrial of fld "beliefstatements" into fld "conclusion"
show fld "premise1"
show fld "premise2"
show image "line"
show fld "conclusion"
put the ticks into startticks
put the milliseconds into startmilliseconds
put "responseneeded" into keypress
put "enabled" into buttonresponding
put "0" into fld "keypress"
send check to this card in 3 seconds
put "responseneeded" into keypress
put "enabled" into buttonresponding
put "0" into fld "keypress"
put flushevents ("keydown") into trash
break
end switch
put flushevents ("keydown") into trash
end if
end keydown
on warningmsg
if the text of fld "keypress" is "0" then
put "Time is almost up!" into fld "timer"
show fld "timer"
put "yes" into fld "warningmsggiven"
send check2 to this card in 2.5 seconds
end if
end warningmsg
on timeout
repeat for each line aLine in the pendingMessages
if aLine contains "check" then
cancel item 1 of aLine
end if
end repeat
repeat for each line aLine in the pendingMessages
if aLine contains "check2" then
cancel item 1 of aLine
end if
end repeat
---exit timeout if a key has been pressed:
if the text of fld "keypress" is "1"then
exit timeout
end if
if the text of fld "warningmsggiven" is "no" then
exit timeout
end if
---
set the itemdelimiter to tab
put "disabled" into buttonresponding
put "1" into fld "keypress"
put " " into fld "timer"
put "questiontime" into keypress
put "no" into fld "warningmsggiven"
hide fld "timer"
show fld "warning"
wait 3 seconds
hide fld "warning"
add 1 to btrial
switch
case btrial = 25
hide fld ("instructions"&condition)
hide fld "warning"
hide fld "conclusion"
hide image "line"
hide fld "premise2"
hide fld "premise1"
hide fld "Iremind"
hide fld "Dremind"
wait 1 seconds
show fld "end"
show btn "end"
break
case btrial <25
repeat with a = 1 to 2
hide fld ("premise"&a)
end repeat
hide fld "conclusion"
hide image "line"
hide fld "Iremind"
hide fld "Dremind"
wait 1 seconds
put item 4 of line btrial of fld "beliefstatements" into fld "premise1"
put item 5 of line btrial of fld "beliefstatements" into fld "premise2"
put item 6 of line btrial of fld "beliefstatements" into fld "conclusion"
put flushevents ("keydown") into trash
show fld "premise1"
show fld "premise2"
show image "line"
show fld "conclusion"
send check to this card in 3 seconds
put "0" into fld "keypress"
put "responseneeded" into keypress
put "enabled" into buttonresponding
break
end switch
end timeout
on check
if the text of fld "keypress" = "0" then
send warningmsg to this card
end if
end check
on check2
if the text of fld "keypress" = "0" then
send timeout to this card
end if
end check2
Re: help with cancelling and reinstating send command....
Posted: Tue Jan 13, 2015 5:37 am
by Simon
Hi Kelly,
If you use the Message Box the 5th icon over is Pending Messages and you can watch which gets cleared.
Simon
Re: help with cancelling and reinstating send command....
Posted: Mon Jan 19, 2015 1:59 am
by kjon2010
Thanks Simon, I never realized that the message box could do that!
So i now have confirmation that the messages aren't being cleared.....is there a sure fire way to clear handlers?
Re: help with cancelling and reinstating send command....
Posted: Mon Jan 19, 2015 2:22 am
by Simon
Hi Kelly,
There is the uncaring way;
Code: Select all
repeat for each line aLine in the pendingMessages
cancel item 1 of aLine
end repeat
That will kill everything.
Simon