Problem with clock elapsedtime element after resettime


Author
Message
DCole9
DCole9
Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)
Group: Forum Members
Posts: 42, Visits: 220
Hi all!...Hi Dave!

I'm having an issue where I want to pause a clock from counting down until a subject presses a button, and only then start counting down, before timing out the trial if they take too long.  I have succeeded in getting the clock to pause and start upon a press.  What I cannot achieve is getting the trial to check the clock's elapsed time, if it is above xxxx milliseconds then branch to my timeout trial.

Here is some sample code from my  experiment.  I have tried both checking the clock's elapsed time and it's currenttime.  Is it just a syntax issue?

<trial myexp_easy>
/stimulusframes = [1 = easytasktext3, targetbar, targetprogress, easytaskpress]
/isvalidresponse = [trial.myexp_easy.response == values.handednessoppcode]
/ontrialbegin = [if (values.easypressed == 0) clock.easytimer.pause()]
/ontrialbegin = [if (values.easypressed == 1) clock.easytimer.resettime();]
/ontrialbegin = [if (values.easypressed == 1) clock.easytimer.start()]
/branch = [if (clock.easytimer.elapsedtime > 7000) trial.feedback]

/ontrialbegin = [values.rewardamount = text.easytask.item.1]
/ontrialbegin = [values.diceoutcome = text.diceroll.item.1]
/ontrialbegin = [values.probwinitem = text.probwinchance.item.1]
/ontrialend = [values.easytrialpicked = 1]
/ontrialend = [if (trial.myexp_easy.response == values.handednessoppcode) values.easypressed += 1]
/ontrialend = [if (trial.myexp_easy.response == values.handednessoppcode) values.totaleasyresponsecount += 1]
/ontrialend = [if (trial.myexp_easy.response == values.handednessoppcode) values.targetprogresssize += 1.515%]
/ontrialend = [values.trialelapsedtime += trial.myexp_easy.elapsedtime]
/ontrialend = [values.easypressrate = (values.trialelapsedtime / values.easypressed)]
/ontrialend = [if (block.myexp_easy.elapsedtime >= 7000) values.easypressrate = (7000 / values.easypressed)]


Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 13K, Visits: 104K
A /branch is executed when the trial ends; a trial ends either when a response has been provided or after a pre-set time if either /timeout or /trialduration are specified. Your trial appears to expect a response (as per its /isvalidresponse) -- if you want it to end automatically after a given amount of time / if no response is received, define a /timeout. You can then /branch based on the response being 0

/ branch = [ if (trial.myexp_easy.response == 0) trial.feedback]

I'm frankly not sure whether the above answers your questions or solves the problem. The issue here is that it is not possible for me to glean what the code you posted is actually supposed to do -- too many relevant things are missing from that small excerpt. It would be helpful if you could actually provide a small stripped-down, self-contained and ideally annotated example, i.e., something that can actually be run and where (only) the key components are included in context: The clock, the logic you use to start / stop it, but none of the things (other stimuli, trials, blocks) that are irrelevant to the question at hand. Thanks.


Edited 8 Years Ago by Dave
DCole9
DCole9
Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)
Group: Forum Members
Posts: 42, Visits: 220
Here is a standalone version that simulates a single trial in my experiment.  Note that I made each button press a trial so that I can refresh the size of the bar as they get closer to completing the required button presses.

To test::  Press L to fill the bar.  Run again and wait a little, then begin pressing L but do not complete.  You will see the timer gets down to 0 but will not branch to the trial.feedbacklost.
What I want::  The timer should only start (both visually and logically) when they FIRST press the L key.  If the timer reaches 0 they should branch to a feedbackfailed trial.

Thanks so much for your help.  Please let me know if you need any additional information or have questions for me.




DCole9
DCole9
Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)
Group: Forum Members
Posts: 42, Visits: 220
<values>
/easypressed = 0
/targetprogresssize = 0%
/rewardamount = 0
/probwinitem = 0
</values>


<shape targetbar>
/shape = rectangle
/position = (50%, 95%)
/color = (red)
/size = (5%, 50%)
/erase = false
/valign = bottom
</shape>

<shape targetprogress>
/shape = rectangle
/position = (50%, 95%)
/color = (green)
/size = (5%, values.targetprogresssize)
/erase = false
/valign = bottom
</shape>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<expt myexpt>
/blocks = [1=easytask]
</expt>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<block easytask>
/bgstim = (easytimer)
/trials = [1-33=easytrial]
/branch = [if (values.easypressed == 33) block.easytaskcompleted]
</block>

<block easytaskcompleted>
/trials = [1=feedbackcompletedtrial]
</block>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<trial easytrial>
/stimulusframes = [1 = targetbar, targetprogress]
/validresponse = (38)
/ontrialbegin = [if (values.easypressed == 0) clock.easytimer.pause()]
/ontrialbegin = [if (values.easypressed == 1) clock.easytimer.resettime()]
/ontrialbegin = [if (values.easypressed == 1) clock.easytimer.start()]
/branch = [if (clock.easytimer.elapsedtime > 7000) trial.feedbackfailed]

/ontrialbegin = [values.rewardamount = "$1.00"]
/ontrialbegin = [values.probwinitem = "12%"]
/ontrialend = [if (trial.easytrial.response == 38) values.easypressed += 1]
/ontrialend = [if (trial.easytrial.response == 38) values.targetprogresssize += 1.515%]
</trial>

<trial feedbackcompletedtrial>
/stimulusframes = [1 = completed]
/timeout = 2000
</trial>

<trial feedbackfailed>
/stimulusframes = [1 = timedout]
/timeout = 2000
</trial>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<text completed>
/items = ("You completed the task.")
/position = (50%, 50%)
/fontstyle = ("Arial", 5%, true, false, false, false, 5, 0)
</text>

<text timedout>
/items = ("You failed to complete the task.")
/position = (50%, 50%)
/fontstyle = ("Arial", 5%, true, false, false, false, 5, 0)
</text>


<clock easytimer>
/position = (20%, 35%)
/format = "ss"
/mode = timer
/fontstyle = ("Arial", 7.5%, true, false, false, false, 5, 0)
/txcolor = (black)
/txbgcolor = (white)
/fontstyle = ("Arial", 10%)
/erase = false
/timeout = 7000
</clock>





Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 13K, Visits: 104K
Okay, thanks. That code is very helpful in that it clarifies the question and what you want to achieve. As I said in my initial reply, your trial needs a timeout; and you'll want to adjust that timeout based by the time elapsed from trial to trial. I.e.:

<values>
/easypressed = 0
/timeleft = 0
/stopblock = false
/targetprogresssize = 0%
/rewardamount = 0
/probwinitem = 0
</values>

<shape targetbar>
/shape = rectangle
/position = (50%, 95%)
/color = (red)
/size = (5%, 50%)
/erase = false
/valign = bottom
</shape>

<shape targetprogress>
/shape = rectangle
/position = (50%, 95%)
/color = (green)
/size = (5%, values.targetprogresssize)
/erase = false
/valign = bottom
</shape>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<expt myexpt>
/blocks = [1=easytask]
</expt>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<block easytask>
/onblockbegin = [values.stopblock = false]
/bgstim = (easytimer)
/trials = [1-33=easytrial]
/ stop = [values.stopblock]
/branch = [if (values.easypressed == 33) block.easytaskcompleted]
</block>

<block easytaskcompleted>
/trials = [1=feedbackcompletedtrial]
</block>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<trial easytrial>
/stimulusframes = [1 = targetbar, targetprogress]
/validresponse = (38)
/ontrialbegin = [if (values.easypressed == 0) {clock.easytimer.pause(); values.timeleft = 999999999}]
/ontrialbegin = [if (values.easypressed == 1) clock.easytimer.resettime()]
/ontrialbegin = [if (values.easypressed == 1) {clock.easytimer.start(); values.timeleft = 7000}]


/ontrialbegin = [values.rewardamount = "$1.00"]
/ontrialbegin = [values.probwinitem = "12%"]
/ontrialend = [if (trial.easytrial.response == 38) values.easypressed += 1]
/ontrialend = [if (trial.easytrial.response == 38) values.targetprogresssize += 1.515%]
/ontrialend = [values.timeleft -= trial.easytrial.elapsedtime]

/branch = [if (trial.easytrial.response == 0) trial.feedbackfailed]
/ timeout = values.timeleft
</trial>

<trial feedbackcompletedtrial>
/stimulusframes = [1 = completed]
/timeout = 2000
</trial>

<trial feedbackfailed>
/ ontrialbegin = [values.stopblock = true]
/stimulusframes = [1 = timedout]
/timeout = 2000
</trial>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<text completed>
/items = ("You completed the task.")
/position = (50%, 50%)
/fontstyle = ("Arial", 5%, true, false, false, false, 5, 0)
</text>

<text timedout>
/items = ("You failed to complete the task.")
/position = (50%, 50%)
/fontstyle = ("Arial", 5%, true, false, false, false, 5, 0)
</text>

<clock easytimer>
/position = (20%, 35%)
/format = "ss"
/mode = timer
/fontstyle = ("Arial", 7.5%, true, false, false, false, 5, 0)
/txcolor = (black)
/txbgcolor = (white)
/fontstyle = ("Arial", 10%)
/erase = false
/timeout = 7000
</clock>


DCole9
DCole9
Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)Distinguished Member (4.4K reputation)
Group: Forum Members
Posts: 42, Visits: 220
Ah I hadn't even thought of doing it like that.  I had a timeout for the block but it was running down the clock even though they hadn't pressed.  The /stop in the block elements is crucial for this to work properly, thanks a lot Dave!

Enjoy your weekend!
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Explore
Messages
Mentions
Search