Howdy, Stranger!

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

Supported by

Question about exp.set function

edited February 2017 in OpenSesame

For my experiment, I am trying to set up the basic response counterbalancing, such as the one in the lexical decision example experiment. I made the inline_script object at the very start of the experiment (see picture)

Then I put up a sketchpad called Instructions, with the following text:
If the face is HAPPY, press [happy_response]
If the face is FEARFUL, press [fear_response]

However, when I attempt to run this, I get an error message, informing me that variable "happy_response" does not exist. The variable is present in the variable inspector, and its source listed as this inline_script (again, see picture), however in spite of my using exp.set function, OpenSesame does not assign the value to the variable, nor does it recognise it when it's called in the sketchpad.

Any ideas? I tried different order of the commands, checked a hundred times that the spelling is identical all over, but nothing changes. I am new to the software, but I read the manual and I really can't tell that I did anything wrong.

Comments

  • Hi,

    To understand the problem, you need to understand the prepare-run strategy that OpenSesame uses. Every item from a sequence is called twice: first to prepare, and then to run. In your case, you define your variables in the run phase of your inline_script. Because the sketchpad is prepared during the prepare phase (which comes first) the variables don't exist yet. Does that make sense?

    So the solution is to move your code to the prepare tab of the inline_script.

    See also:

    Incidentally, exp.set() is outdated. The modern way to interact with experimental variables is to use the var.var_name syntax. See:

    Cheers,
    Sebastiaan

  • edited February 2017

    Hi,

    thank you, that worked like a charm! :smile:
    However, now I have a different problem, again with the inline script. I tried to create a script to tell the program which response is correct, which looks like this:

    However, as you can see in the variable inspector, no matter what I do the accuracy is 0.
    What did I mess up this time? :dizzy:

  • Hi,

    There are a few things wrong here. The first has to do with Python syntax:

    var.emotion = 'Happy' or 'Fear'
    

    As they say, I don't think this means what you think it means. You can find some background information about using and and or with strings here:

    But basically, if you want to make a random choice, you can do something like this:

    var.emotion = 'Happy' if sometimes() else 'Fear'
    

    Regarding setting var.correct_response: The expected value is a semicolon-separated string, not a list. So you'll simply want to do:

    var.correct_reponse = var.happy_response
    

    Cheers,
    Sebastiaan

Sign In or Register to comment.