Howdy, Stranger!

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

Supported by

Mouse Trap - Assigning buttons to variables


I am quite new to OpenSesame and programming in general so this may be a dumb question.

I am presenting three pictures and want participants to click on of these three. If it is incorrect they will be shown an error screen and will be shown the images again. If they are correct I want to show a correct screen and they can move on to the next part of the experiment.

I have created graphics of the three images and what I want them to look like and insertedthese as an image in sketchpad. I decided to use MouseTrap plugin as it looked like a good option for defining areas of the pictures.

Following this tutorial I have drawn borders around my buttons using rect elements. The next part of the tutorial says "Insert the button labels using textline elements. You may either use a constant string or an experimental variable (e.g., '[CategoryLeft]')." I am not exactly sure how to do this...its probably really obvious but in the sketchpad do I go into the script and define them there (if so what would that look like) or would I put the whole thing into a loop and define variable there or both?

Sorry if this is really obvious.

Thanks in advance.



  • Hi Matt,

    the quoted part relates to inserting the actual labels as text on the screen. What you mean is naming the rect elements, i.e., what is described afterwards:

    "If in the following variant 3a is used to define buttons (the easier and preferred variant as of OpenSesame 3.2), an additional step is required: To make the button borders identifiable, the rect elements are labeled using the Name field in the top row of the sketchpad options (this field is available after selecting the rect element). Each button border is named using the corresponding variable name from the previous step 2 (e.g., '[CategoryLeft]')."

    You can also have a look at the preprint of a book chapter that describes this and contains a screenshot (Figure 2):

    When naming the elements, you can either use text, e.g., "Image1", "Image2" etc. However, in case you have several trials and your images vary you can also use variables. All of this depends on how you have set up the general structure of your experiment. If you have several trials with different images, you probably want to use a loop where you create variables that specify the name of the image files (e.g. ImageFile1, ImageFile2 etc.). Then you use these variables to define your images and also to name the rectangles as explained above (entering "[ImageFile1]", "[ImageFile2]", etc.

    However, in you case it could also make sense to use OpenSesame's form plugins and the ImageButton widget (

    Hope this helps. Let me know if you have additional questions.



  • Hi Pascal,

    Sorry for the late reply. Thanks for the help and the link to the pre-print! I have managed to now assign the three different sections of my images to three different buttons.

    So now I am trying to run certain images that will appear if the click one of the three buttons but I am having problems and the wrong images are being produced after my clicks. I am not sure if I am giving the correct "run if" statements for the feedback images.

    Just to explain I have three different questions with images that are identical they all have the same buttons (a left, a middle and a right button) but the correct response will different depending on the question (I have used the looper to define CategoryCorrect as either CategoryLeft, CategoryMiddle, CategoryRight)

    My experiment is laid out as so

    • A Looper (defining the 3 different buttons and three different questions)
    • A sequence that contains the three questions
    • The three question sequences

    My question sequences looks like this:

    • Sketchpad (with three buttons)
    • Mousetrap response
    • Correct Feedback Image
    • Incorrect Feedback Image one
    • Incorrect Feedback Image two
    • Repeat cycle (to repeat this sequence if incorrect response given)
    • Logger

    I have tried using the run if statement for correct: "[correct] = 1" . For the incorrect ones I have tried telling it to present the image when the incorrect response is played and gave coordinates so it knows which of the two incorrect images to display: "[correct] = 0 and x > 64.

    This is not giving me the correct feedback images that correspond to mouse clicks. This is probably very easy but is there another mouse response variable that I should be using for the run if section?

    Sorry this is probably a very easy problem but I haven't found a solution yet!



  • Hi,

    Sorry I have since found a solution to my problem above.

    I used a bit of python code in the 'run if' statement that has made things work.

    I created a sequence after the mousetrap response item that contained the three response pictures I wanted to show. In the 'run if' column I used a response_mouse variable to tell the programme when to play which feedback picture.

    For example, if my participants clicked on the second button and I wanted that picture to flash I used this run if statement:

    " =var.response_mouse1=='Character2' "

    That was probably obvious for some of you but I hope that's helpful for anyone else running a similar design.



Sign In or Register to comment.