Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Text input response variable

edited October 2018 in OpenSesame

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()

        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
        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:

  1. Is this the correct way?
  2. I am getting an empty log file with no variables in it

I would be grateful if anyone could help me in this.


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.


  • Hi,

    Is this the correct way?

    Not quite. Don't use input_<number> as variable, but the string you assigned to var, so in your case first_letter, etc.

    I am getting an empty log file with no variables in it

    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()


  • edited October 2018

    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
    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.


  • 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 because cap_text is empty.

    Your logic makes sense in principle, the problem is that the variables text, and cap_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,


Sign In or Register to comment.