Branching dependent on input + key press question


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 inQuisit experts,
I'm a new inQuisit user so I very much appreciate any helpful tips/tutorials/things to check out for finding out the solutions to my problems.  My problems are as follows:

I'm programming an experiment which involves the participant deciding between 2 types of tasks on every trial.  
1) The first problem I'm having is branching the main selection trial to the trial that they choose.  Here's an example of the code that I am trying to use:
/branch = [if (trial.maintrial.response == values.responsekeyhard) trial.maintrial_hard]
/branch = [if (trial.maintrial.response == values.responsekeyeasy) trial.maintrial_easy]

Ideally when the subject presses "responsekeyhard" it bring them to the hard trial, and likewise for the easy response/trial.

2) I was wondering if anyone had an example of code that could count the number of key presses during a trial or could point me to a resource to help.  My goal is to count key presses while updating an image (filling a bar) until they reach the goal criterion of key presses.

Thank you very much!
Dan


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
Re. #1: The /branch attributes are okay syntax-wise. The respective /branch will execute when the trial's response property equals the specified <values> entry. You'll thus want to check whether that matches. Note that for key presses, the response property returns a given key's *scancode*, not a key's "literal" value.

Re. #2: In Inquisit, a <trial> element registers a *single* response. You cannot register *multiple* key presses in a single instance of a <trial>. The usual approach is to run multiple (instances of) trials -- each one registering a single press -- a sum up the number of key presses in a <values> entry via /ontrialend:

<values>
/ spacebarpresscount = 0
</values>

<block myblock>
/ trials = [1=mytrial]
</block>

<trial mytrial>
/ ontrialend = [if (trial.mytrial.response == 57) values.spacebarpresscount += 1]
/ stimulusframes = [1=mytext]
/ validresponse = (57,28)
/ branch = [if (trial.mytrial.response == 57) trial.mytrial]
</trial>

<text mytext>
/ items = ("Number of times you pressed the SPACEBAR: <%values.spacebarpresscount%>. Press ENTER to terminate")
</text>

Edited 10 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
Hi Dave, thank you very much for the response.  It is very helpful!

I'm not sure why my code doesn't appear to be working however since I am using the scan codes for the responses.  Since the /branch looks to be working properly maybe there is a problem with my trials that are being branched to.  Currently what is happening is it initiates trial main which asks for the decision of easy or hard.  When I press the key to choose a difficulty it appears to keep calling trial.main since the screens display should change to the maineasy screen but it continues to present easy/hard decisions.  Do you have any recommendations of where to look in my code for inconsistencies?  Or maybe it would be helpful to upload my program?  Thank you again for your support.

Dan

/responsekeyeasy = 31
/responsekeyhard = 38

<trial main>
/ontrialbegin = [values.stiminterval = list.stimulusinterval.nextvalue]
/ontrialbegin = [text.easytask = list.easyrewardamount.nextvalue]
/ontrialbegin = [text.hardtask = list.hardrewardamount.nextvalue]
/ontrialbegin = [text.probwinchance = list.probwin.nextvalue]
/ontrialbegin = [trial.main.insertstimulustime(text.probwinchance, values.stiminterval)]

/stimulustimes = [0 = focus, probwinchance, probtext, easytask, easytasktext, hardtask, hardtasktext]
/validresponse = (31, 38)
/correctresponse = (38)
/ontrialend = [trial.main.resetstimulusframes()]
/pretrialpause = values.pause
/timeout = 5

/branch = [if (trial.main.response == values.responsekeyhard) trial.main_hard]
/branch = [if (trial.main.response == values.responsekeyeasy) trial.main_easy]

/ontrialend = [if (trial.main.response == values.responsekeyhard) values.choseHard ="HARD" else values.choseHard = "EASY"]

</trial>

<trial main_easy>
/ontrialbegin = [values.rewardamount = text.easytask]
/stimulustimes = [0 = probwinchance, easytask, easytasktext]
/timeout = 7
/ontrialend = [trial.main_easy.resetstimulusframes()]
/branch = [trial.main]
</trial>


<trial main_hard>
/ontrialbegin = [values.rewardamount = text.hardtask]
/stimulustimes = [0 = probwinchance, hardtask, hardtasktext]
/timeout = 21
/ontrialend = [trial.main_hard.resetstimulusframes()]
/branch = [trial.main]
</trial>

<block mainblock>
/onblockbegin = [text.focus.textcolor = values.focuscolor; text.focus.textbgcolor = values.screencolor]

/trials = [1-5= main]
/onblockbegin = [block.mainblock.screencolor = values.screencolor]
/preinstructions = (instruct)
/postinstructions = (endofexp)
/stop = [trial.main.count == values.maxtrialnumber]
</block>




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
You have a 5ms /timeout in <trial main>. That's way to short to actually ever register a response and branch accordingly.

What's worse is that /pretrialpause is included in /timeout. So there's actually *no* time to register a response at all. See the "How to Control Trial Duration and Inter-Trial Intervals" topic in the documentation for details.

Similar problems (too short /timeout) affect your other <trial> elements.

Finally, it is unclear why you /branch back to trial.main from your easy / hard trial elements while at the same time running trial main 5 times via the <block>.

Edited 10 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
Oops!  Thank you.  I thought it was in terms of seconds- now that I think of it ms makes a lot more sense...  I switched it to reflect what I wanted but the key press still does not register/switch to the appropriate next trial.
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
Since I don't know other parts of your code, I cannot tell you where exactly the error/s is/are. What I can tell you is that

<values>
/responsekeyhard = 38
/responsekeyeasy = 31
</values>

<block myblock>
/ trials = [1-4=main]
</block>

<trial main>
/stimulustimes = [0=debug]
/validresponse = (31, 38)
/correctresponse = (38)
/pretrialpause = 500
/timeout = 5000
/branch = [if (trial.main.response == values.responsekeyhard) trial.main_hard]
/branch = [if (trial.main.response == values.responsekeyeasy) trial.main_easy]
</trial>

<trial main_hard>
/stimulustimes = [0=debug]
/validresponse = (57)
</trial>

<trial main_easy>
/stimulustimes = [0=debug]
/validresponse = (57)
</trial>

<text debug>
/ items = ("<%script.currenttrial%>")
</text>

works perfectly fine for me, i.e., the issue is not with the branching.

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 Dave, thanks again for your help so far.  Is there anyway I can send you my code privately for you to take a look at?  My response keys do not trigger new trials and I am not sure why.  I suspect something is going wrong with my display of the text or perhaps my keys are not registering for some reason?  Are there any known issues with Mac Books not properly outputting the response key codes?
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
Sure. You can either attach the script to this thread (see the +Insert controls at the bottom of the editor) or do the same via a private message if you'd prefer not to post the script publicly.

As for scancode issues on MacBooks: I am not aware of any. You should, however, check the data file's 'response' column to see whether the recorded scancodes match those you specified in your script or if there aren't any responses registered at all.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Explore
Messages
Mentions
Search