Millisecond Forums

Off-by-one error when setting correctresponse and getitem via value

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

By Jack S. - 10/5/2018

Hello all,

I'm creating a modified version of the Digit Symbol Substitution Task in which the symbols are displayed one at a time (rather than in a large grid, as in the more common implementation of the task). At the beginning of each trial, the script selects a random value between 1 and 9, which determines both what symbol to display and what answer is correct for that trial. The problem I'm encountering is that the correct response seems to be off by one; i.e., if the random value is 5, the 5th symbol is displayed (confirmed via debug window), but "4" is treated as the correct answer. Even more confusingly, in trial data from monkey mode, the problem seems to disappear; if a trial's random value is 7, then a response of "7" is coded as correct.

 Any idea what might be causing this? I've included my code below; the problem is easiest to spot if you run the digit_sub_practice block. Please let me know if I can provide any additional info!


****************************
PARAMETERS/VALUES
****************************

<parameters>
/substitution_post_stim_pause = 100
/substitution_feedback_duration = 500
</parameters>

<values>
/trialtype = ""
/substitution_complete = 0
/task_order = 99
</values>

Symbol to display is determined by current_symbol, which is set randomly at start of each trial.

<values>
/ current_symbol = ""
/ total_digit_sub_trials = 0
</values>


********************
SYMBOL RANDOMIZATION
********************

A list to select which of the nine symbols to display, and thus determine which answer is correct:

<list random_pick>
/ items = (1-9)
/ select = random
/ resetinterval = 1
</list>


The symbols themselves:

<item symbols>
/1 = "Л"
/2 = "◇"
/3 = "ϴ"
/4 = "Ш"
/5 = "σ"
/6 = "Џ"
/7 = "Г"
/8 = "Λ"
/9 = "Ҩ"
</item>

The key (from original implementation of DSST):

<picture key_pic>
/items = ("key.png")
/vposition = (75%)
/ erase = false
</picture>


*************
STIMULI
*************

The symbol display itself:

<text symbol_display>
/ items = ("<% getitem(item.symbols, values.current_symbol) %>")
/ fontstyle = ("Helvetica", 25%)
/ vposition = 33%
</text>


Feedback in case of error, and helpful instructions:

<text DSST_error>
/ items = ("X")
/ vposition = 33%
/ fontstyle = ("Helvetica", 40%)
/ color = red
/ halign = center
/ hjustify = center
</text>

<text DSST_feedback>
/ items = ("Refer to key below")
/ vposition = 50%
/ fontstyle = ("Helvetice", 5%)
</text>

Feedback if correct:

<text DSST_correct>
/ items = ("✓")
/ vposition = 33%
/ fontstyle = ("Helvetica", 40%)
/ color = green
/ halign = center
/ hjustify = center
</text>


*************
TRIALS
*************


<trial DSST_main>
/ ontrialbegin = [ values.current_symbol = list.random_pick.nextvalue ]
/ stimulustimes = [ 0 = symbol_display ]
/ validresponse = ("1", "2", "3", "4", "5", "6", "7", "8", "9")
/ correctresponse = (values.current_symbol)
/ ontrialend = [ values.total_digit_sub_trials += 1 ]
/ branch = [ trial.DSST_main ]
/ posttrialpause = parameters.substitution_post_stim_pause
</trial>


<trial DSST_practice>
/ ontrialbegin = [ values.current_symbol = list.random_pick.nextvalue ]
/ stimulustimes = [ 0 = symbol_display ]
/ validresponse = ("1", "2", "3", "4", "5", "6", "7", "8", "9")
/ correctresponse = (values.current_symbol)
/ posttrialpause = parameters.substitution_post_stim_pause
/ errormessage = true(text.DSST_error, parameters.substitution_feedback_duration)
/ correctmessage = true(text.DSST_correct, parameters.substitution_feedback_duration)
</trial>


<block digit_sub_practice>
/ onblockbegin = [ values.trialtype = "Practice" ]
/ trials = [ 1-10 = DSST_practice]
/ bgstim = (key_pic)
/ branch = [ block.digit_sub_main ]
</block>


<block digit_sub_main>
/ onblockbegin = [ values.trialtype = "DSST" ]
/ trials = [ 1 = DSST_main]
/ bgstim = (key_pic)
/ timeout = 120000
/ onblockend = [
values.task_order += 1;
values.substitution_complete = values.task_order;
values.trialtype = "";
]
</block>



By Jack S. - 10/5/2018

And here's the key itself -- my apologies, should have included it with the original post.
By Dave - 10/5/2018

Jack S. - Friday, October 5, 2018
And here's the key itself -- my apologies, should have included it with the original post.

It's not an off-by-one error, the problem is this:

/ validresponse = ("1", "2", "3", "4", "5", "6", "7", "8", "9")
/ correctresponse = (values.current_symbol)

You've defined the digits 1 to 9 as valid responses. A trial's response property, however, never reflects the character imprinted on the key (e.g. the digit "3" or "7" on the number keys at the top of your keyboard, or the letter "E", etc.), but the respective key's numerical keyboard scancode. See https://www.millisecond.com/support/docs/v5/html/language/scancodes.htm and Tools -> Keyboard Scancodes...

The scan code for the digit "1" key is 2, the scan code for the digit "2" key is 3 and so forth. That's where the mismatch comes from.

If you do

<trial DSST_practice>
/ ontrialbegin = [ values.current_symbol = list.random_pick.nextvalue ]
/ ontrialbegin = [ values.current_scancode = computer.chartoscancode(values.current_symbol)]
/ stimulustimes = [ 0 = symbol_display ]
/ validresponse = ("1", "2", "3", "4", "5", "6", "7", "8", "9")
/ correctresponse = (values.current_scancode)
/ posttrialpause = parameters.substitution_post_stim_pause
/ errormessage = true(text.DSST_error, parameters.substitution_feedback_duration)
/ correctmessage = true(text.DSST_correct, parameters.substitution_feedback_duration)
</trial>

with

<values>
/ current_symbol = ""
/ current_scancode = ""
/ total_digit_sub_trials = 0
</values>

then things should work fine.
By Jack S. - 10/5/2018

Works like a charm -- thank you so much!

Just to make sure I understand: is it accurate to say that /correctresponse interprets numbers inside of quotes ("5") as characters, and numbers without quotes (5) as scancodes? Similarly, in the response column of the data file, a 7 refers to the keycode, not to the 7 key being pressed?
By Dave - 10/5/2018

Jack S. - Friday, October 5, 2018
Works like a charm -- thank you so much!

Just to make sure I understand: is it accurate to say that /correctresponse interprets numbers inside of quotes ("5") as characters, and numbers without quotes (5) as scancodes? Similarly, in the response column of the data file, a 7 refers to the keycode, not to the 7 key being pressed?

Yes, that is absolutely correct.