Howdy, Stranger!

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

Supported by

[solved] Coding help for numerical keyboard response post sequence

edited January 2016 in OpenSesame

Hi there,

I'm having a little trouble with coding for my experiment and would really appreciate some guidance.

Essentially, I am creating a counting task in which I am hoping to show participants a block of 15 stimuli in each sequence. After each I would like to ask a question, e.g. "how many faces did you see" and they would need to enter a keyboard response.

I am relatively new to coding and to OpenSesame (but I love the software already!). I am guessing that it might be possible to achieve this by creating a loop after my trial sequence, inserting a sketchpad and altering the script on this to insert a keyboard and numerical response. But as a newbie this is a little beyond my capabilities!

Any advice on this (or coding if possible) would be greatly appreciated!
Thank you!


  • edited 3:11AM


    If I understand correctly, one trial consists of 15 stimuli, followed by a question and a keyboard response?

    You could do this in multiple ways. The most straightforward way might be to just place 16 sketchpads in your trial sequence, 15 of which will display an image, and the 16th your question. But of course you want to control what kind of images are displayed. In the sketchpad item you can click "view script" in the upper-right corner, and write a line of code like draw image 0 0 "[image1].png" scale=1 center=1 show_if="always". This will grab an image from the filepool with its name corresponding to whatever text the variable image1 contains. For instance, you may have stated somewhere that image1 = "face". In this case, the first image is going to be "face.png" (given that this file was indeed in your file pool).

    Long story short, it comes down to defining what your sequence of images should look like for each trial. You can do this in an inline_script prior to to the sketchpads (but also in your trial sequence). I imagine this may depend on an experimental condition? Say you have amount_of_faces as condition, which could be set to 4, 6 or 8. In that case your inline script could look like this:

     images = [] # an empty list that will be given 15 elements.
     for i in range(0,exp.get("amount_of_faces")):
           images.append("face") # appends element "face" to the list
                                              # as many times as "amount_of_faces" dictates
     for i in range(0, 15-exp.get("amount_of_faces")):
           images.append("house") # appends "house" to the list until it contains 15 elements
     random.shuffle(images) # shuffles the list

    Now, in the line of code in each sketchpad, you use "[images[0]].png", "images[1]].png", "images[2].png", all the way up to "images[14].png" for your 15th sketchpad. Note that you're using only two images in this sequence: a face and a house. If you have multiple faces and houses (or whatever you want to display), this will complicate the code that builds up your sequence a bit - but the logic will stay the same.

    Let me know how it goes.



  • edited 3:11AM

    Thank you for the response Josh!

    Very useful and informative, however I am still having a small issue (but I don't think I described it properly to begin with).

    At present, I have managed to code one sketchpad to show the 15 stimuli in a random order. But I am still having a problem with the keyboard response.

    My experiment loop consists of a sequence which contains; a fixation dot, a blank sketchpad, an advanced delay and then the stimulus sketchpad. When I enter in a keyboard response, blank screen and logger file after this (in order for the participant to enter the amount of faces (targets) in the sequence) this affects the entire sequence and it will not run correctly. So I have tried to enter it after the trial sequence but I still seem to be having problems.

    Is there a way to use a sketchpad to show the question, e.g. "how many faces did you see?" and allow the participant to respond? and where should this be located in relation to the rest of the experiment.

    I apologise if this doesn't seem like a clear explanation.

    Thank you so much for your help so far - it is greatly appreciated!

  • edited 3:11AM

    I managed to solve the issue! Thank you for all of your help with the coding for the pictures.

    I ended up adding a sequence for the response after the trial sequence consisting of a form text input screen and logger. This has solved the issue - such a simple solution in the end!

    Thank you again Josh for your previous advice!

Sign In or Register to comment.