ontrialend not reading response correctly?


Author
Message
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: 105K
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>

Edited 8 Years Ago by Dave
mzhang13
mzhang13
Associate Member (239 reputation)Associate Member (239 reputation)Associate Member (239 reputation)Associate Member (239 reputation)Associate Member (239 reputation)Associate Member (239 reputation)Associate Member (239 reputation)Associate Member (239 reputation)Associate Member (239 reputation)
Group: Forum Members
Posts: 3, Visits: 34
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>
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Explore
Messages
Mentions
Search