Millisecond Forums

ontrialend not reading response correctly?

https://forums.millisecond.com/Topic20853.aspx

By mzhang13 - 2/22/2017

Currently, I'm running a task where the participant makes a choice, and a master budget updates by subtracting the price of the selection. However, I noticed that even when pressing "z" only to move on, the conditional in the ontrailend part always goes to the "else" (and updates accordingly). Am I missing something here?

<trial recipe_trial>
/ validresponse = ("z", "m")
/ stimulusframes = [1 = recipe1, recipe2, recipe1_price, recipe2_price, progress]
/ ontrialend = [
if (trial.recipe_trial.response == "z") {
values.current_budget = values.current_budget - list.recipe1_prices.item(picture.recipe1.currentindex)
}
else {
values.current_budget = values.current_budget - list.recipe2_prices.item(picture.recipe1.currentindex)
}
]
/ posttrialpause = 250
</trial>
By Dave - 2/22/2017

mzhang13 - Wednesday, February 22, 2017
Currently, I'm running a task where the participant makes a choice, and a master budget updates by subtracting the price of the selection. However, I noticed that even when pressing "z" only to move on, the conditional in the ontrailend part always goes to the "else" (and updates accordingly). Am I missing something here?

<trial recipe_trial>
/ validresponse = ("z", "m")
/ stimulusframes = [1 = recipe1, recipe2, recipe1_price, recipe2_price, progress]
/ ontrialend = [
if (trial.recipe_trial.response == "z") {
values.current_budget = values.current_budget - list.recipe1_prices.item(picture.recipe1.currentindex)
}
else {
values.current_budget = values.current_budget - list.recipe2_prices.item(picture.recipe1.currentindex)
}
]
/ posttrialpause = 250
</trial>

A <trial>'s response property returns the numerical scan code of the key pressed, not the key's "literal" value (letter or other symbol). The scan code of the "z"-key on a standard English-language keyboard is 44, i.e. your statement ought to read

/ ontrialend = [
if (trial.recipe_trial.response == 44) {
,,,
}
]

See the "Keyboard Scan Codes" topic in the documentation and 'Tools -> Keyboard Scancodes...' for details.

To convert the scan code to the corresponding charcter, you can also use the computer.scancodetochar() function. Like so:

<trial recipe_trial>
/ validresponse = ("z", "m")
/ branch = [
if (computer.scancodetochar(trial.recipe_trial.response) == "z") {
trial.z
}
else {
trial.m
}
]
/ posttrialpause = 250
</trial>

<trial z>
/ stimulusframes = [1=mytext]
/ validresponse = (57)
</trial>

<trial m>
/ stimulusframes = [1=mytext]
/ validresponse = (57)
</trial>

<text mytext>
/ items = ("you pressed <%script.currenttrial%>")
</text>

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