Text input response variable
Hey all!
I am trying to develop a standard version of operation span task for my classroom practical. Currently, I have managed to develop a crude form right now. The number of letters presented varies from 3-7.
I am using custom form to take inputs on recall phase of letters presented and I am also using custom forms to present mathematical problem.
The following code describes the procedure of presenting letters on the screen
import random
import string
letters = list(string.ascii_uppercase)
var.isi = 495
var.letter_dur = 495
stim = random.sample(letters, var.length)
letter_canvas_list = []
letter_canvas = []
for i, stim in enumerate(stim):
letter_canvas = canvas()
letter_canvas.text(stim)
letter_canvas_list.append(letter_canvas)
blank_canvas = canvas()
This code describes the presentation of math problem which precedes the recall phase
n2 = random.randint(0,9)
n3 = random.randint(0,9)
n4 = (n1*n2) + n3
r = [n1,n2,n3,n4]
form1 = Form(
cols=[1,1], rows=[1,2,1],
margins=(50,100,50,100), spacing=25
)
labelTitle = Label(text=u'Question')
labelQuestion = Label(
text=u'Is this correct ({}*{})+{}={}?'.format(*r), center = False
)
buttonYes = Button(text=u'Yes')
buttonNo = Button(text=u'No')
form1.set_widget(labelTitle, (0,0), colspan=2)
form1.set_widget(labelQuestion, (0,1), colspan=2)
form1.set_widget(buttonYes, (0,2))
form1.set_widget(buttonNo, (1,2))
This code describes creating a form with input text option to take response in the recall phase for letters presented earlier.
form2 = Form(
cols=[1,1, 1], rows=[1,1],
margins=(50,100,50,100), spacing=25
)
button_ok = Button(text=u'Ok')
input_first = TextInput(stub=u'1st', var=u'first_letter')
input_second = TextInput(stub=u'2nd', var=u'second_letter')
input_third = TextInput(stub=u'3rd', var=u'third_letter')
form2.set_widget(input_first, (0,0))
form2.set_widget(input_second, (1,0))
form2.set_widget(input_third, (2,0))
form2.set_widget(button_ok, (1,1), colspan=2)
input = [input_first, input_second, input_third]
Now coming to the problem I am facing I am not able to understand what variable from the input text form just mentioned above stores the responses from the subject. Assuming that it is input_first, input_second, input_third variable I coded the following:
for i in range(len(input)):
if input[i]==letter_canvas_list[i]:
var.cor = 1
else:
var.cor = 0
The above code runs through letter_canvas_list and input list and compare if same item is placed on the same index position. The problem I am facing is two fold:
- Is this the correct way?
- I am getting an empty log file with no variables in it
I would be grateful if anyone could help me in this.
Thanks
Vatsal
PS: @sebastiaan can we simulate an experiment before running it. Can we do that using debug window? I tried running canvas commands in the debug window but opensesame kept crashing.
Comments
Hi,
Not quite. Don't use
input_<number>
as variable, but the string you assigned tovar
, so in your casefirst_letter
, etc.Completely empty? Then you probably don't have a logger item. In your experiment, your logger is not in side the sequence, but comes after. I don't think this is what you intended. Maybe put it inside the sequence? Alternatively, you can also do it in an
inline_script
via.var.log_vars()
Eduard
Hey @eduard
Thanks for your reply. Yes indeed I had noticed this input mistake but did not updated it on the forum, my fault.
I have now made few changes in the python inline script. For collecting responses I have created 7 forms which are executed when the length set in the experimental loop matches a specific value. Thus, for length 4 I have a form with 4 text input boxes which is executed when
var.length == 4
Now that I know that the text input response is store in var variable I have also created a separate variable called text what concatenates all the vars in a given text input forms. For example:
form3 = Form( cols=[1,1,1,1], rows=[1,1,1], margins=(50,100,50,100), spacing=25 )
button_ok = Button(text=u'Ok')
input_first = TextInput(stub=u'1st', var=u'first_letter')
input_second = TextInput(stub=u'2nd', var=u'second_letter')
input_third = TextInput(stub=u'3rd', var=u'third_letter')
form3.set_widget(input_first, (0,0))
form3.set_widget(input_second, (1,0))
form3.set_widget(input_third, (2,0))
form3.set_widget(button_ok, (0,2), colspan=2)
concatenating response if the length variable is set to 3. That means 3 letter are presented and then asked to recall those letters by entering them in a text input box.
text = var.first_letter + var.second_letter + var.third_letter
this code then capitalizes all the letters since the letter present in the canvas object are in uppercase.
cap_text = [i.upper() for i in text]
In order to code the correct response I have this for loop to loop through cap_text variable and match it with letter_canvas_list which stores the actual sequence of letters presented. The match is done letter wise and index wise where it is ensured that the same letter is in cap_letter as it is in letter_canvas_list on the same index position in letter_canvas_list.
for i in range(len(cap_text)):
if cap_text[i]==letter_canvas_list[i]:
var.cor = 1
else:
var.cor = 0
I have now inserted the log file in the loop sequence with only the relevant variables to log for.
Coming to the problem I am getting an "NA" on the 'cor' column. I am not sure what is causing this? Any view??
Also I am getting timing issues. After pressing the spacebar or any key on the instruction slide the slid stays there for a while and then the fixation dot appears. Also, the timing of the fixation dot is also delayed in excess of 495 ms. Any ideas as to what this might be causing??
I have attached the updated experiment file.
Thanks
Vatsal
HI Vatsal,
There are a couple of problems with your code. The primary reason the variable
cor
is not defined is that the loop it is located in is being skipped becausecap_text
is empty.Your logic makes sense in principle, the problem is that the variables
text
, andcap_text
are defined before the form is actually executed. I'm actually a bit surprised that the experiment didn't crash.A better way to make this experiment work is to only create a single form, but make its parameters flexible. For example, depending on the number of letters, create lists with the number of columns, rows, and whatever else you need to define the form. And then use these variable to initialize the form. Similarly, you can then add elements to that form, depending on the number of letters. Importantly, once executed, you can collect the responses and define the correct response.
Another thing that yo should keep in mind is that defining a variable in a loop does basically overwrite for as many iterations that you have and the variable (var.cor in your case) will have the value that was assigned to it on the last iteration. IF you want var.cor to be correct only if all letters were recalled correctly, you have to obtain a correct value for each letter separately, and combine the outcome (e.g. with
all()
).Hope this helps,
Eduard
@eduard
I just want to check I have understood your answer above... If so it has highlighted a major flaw in my current experimental design! You say:
"defining a variable in a loop does basically overwrite for as many iterations that you have and the variable (var.cor in your case) will have the value that was assigned to it on the last iteration."
I am presenting nouns in a loop and asking participants to respond with 3 adjectives. Their responses are [adj_1] [adj_2] and [adj_3]. The [noun] displayed comes from the loop for the sequence. Does this mean that the log will only have values for those variables as provided on the final iteration of the loop?
I plan to present a selection of the adjectives back to the participant at the end. Is there a way to have each iteration of the loop save the variable under a different "sub-variable" to be recalled later?
Thank you
Ali
Hi Ali,
If you have placed a logger at the end of the sequence that you loop over, than the values of your variables will be nicely logged for each iteration. They will be overwritten in OpenSesame internally at the next iteration, but not in your log files.
Hi @Daniel thanks so much for clarifying. It would have been a catastrophe if I hadn't realised this before! The second part of my experiments recalls the answers initially given and asks the participants to make a second judgement on them, so I need them saved as separate variables. Thanks again