Howdy, Stranger!

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

Supported by

updating variables in opesesame

appapp
edited June 2016 in OpenSesame

Hi!I am new to opensesame and I am putting together a simple experiment. Participants see two objects on the screen and are asked to press either the M or the Z button on the keyboard. If they click on the M button, they lose one point of out, let's say, 10 points. If they click in the Z button they lose nothing.

I declared after the loop a variable called 'points' as follows - exp.set('points',10)
what I want to do is adding an inline after I collect the responses that updates the var points and display its current value in a sketchpad after each trial.

I tried the following code in the prepare phase of the inline after collecting responses:

if self.get("response")=="z":
    points=points
elif self.get("response")=="m":
    points=points - 1

In the sketchpad I use the [ ] to retrieve the value of points:

  • you are earning [points] points -

But no matter what I click, the sketchpad always shows the value of 10..

I am pretty sure this is an easy question. but for some reasons I cannot figure it out!
thanks all!

Cheers,
A

Comments

  • edited 1:06PM

    Hi A,

    The reason is simply that you don't use exp.set() to update points. You only update the Python variable that lives in your inline_script, but which isn't accessible using the square-brackets notation. Also, as of 3.0, you can use the var.varname notation instead of exp.set(). That's a bit more elegant, but it does the same thing.

    So what you want to do is:

    if var.response == "z":
        var.points = var.points
    elif var.response == "m":
        var.points = var.points - 1
    

    Or, less redundant:

    if var.response == "m":
        var.points -= 1
    

    See also:

    Cheers!
    Sebastiaan

  • appapp
    edited 1:06PM

    Hi Sebastiaan!
    Thanks a lot! I was also running an older version and I could not wrap my head around the error that I was getting while trying to use the var.varname..
    Your solution is very elegant and works smoothly..
    Now I am trying to implement in the same experiment a block in which participants have to click accurately on one pic on the screen (with the mouse). if they click on it, then the accuracy is =1, otherwise is =0. I have been trying to re create the mouse.hit test (I am coming from an extensive eprime background!) but I could not figure out how to give feedback based on the accuracy of the mouse responses..
    do you have any recommendation, or can you direct me towards some relevant info?
    many thanks!

    Cheers,
    Andrea

  • edited July 2016

    Hi Andrea,

    One way would be to use the touch_response plugin, with which you can code mouse click responses based on a grid on the screen (e.g. left side is 0, right side is 1).

    Or you could use a custom form with image_button widgets on it:

    Cheers!
    Sebastiaan

  • appapp
    edited 1:06PM

    Thanks Sebastiaan!
    But the link you kindly provided does not work:-(
    andrea

  • edited 1:06PM

    Ah, right! It should work now. (I removed the .html part.)

Sign In or Register to comment.