Howdy, Stranger!

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

Supported by

[open] Global variable

edited December 2013 in OpenSesame

Hi there, I'm a bit of a noob with Opensesame so this question might sound totally ridiculous.
So, I need to define a variable which can be used by multiple items (sketch pad, keyboard response, logger, etc.). I know such a variable can be defined with exp.set via inline script, the problem is that I don't know how to change the value of the variable during the experiment.

For example, I want the variable value to change depending on the keyboard response, and then for the sketch pad to use that value in displaying new stimuli.

So in short, I need a variable which can be used and changed by any item.

Comments

  • Hi,

    If you want a given variable to have a different value for, for example, every trial, it's more convenient to define this variable via a loop item.

    Did you already read this page?

    If this doesn't answer your question, could you please explain what kind of experiment you're exactly trying to build?

    Cheers,

    Lotje

    Did you like my answer? Feel free to Buy Me A Coffee :)

  • edited 8:15PM

    Yeah, I know about defining variables within a loop. The problem is I need a "free" variable, accessible by multiple items.
    The experiment is meant to use the adjustment method in psychophysics.
    I'd use a sketch pad item, keyboard response item and a repeat cycle item.
    The sketch pad would present an ellipse and the participant would press left or right keys to adjust it in order to make it look as much as possible like a perfect circle, once they're satisfied they would press enter and the repeat cycle would stop.
    I know how to make it work but in order to implement my solution I need a variable not set and changed by the loop, a free global variable that would change depending on the participants response. It would be simple to do if that kind of variable is possible within OpenSesame.
    Define it at the beginning of the experiment and manipulate it later, is it possible or not?

  • edited December 2013

    That's possible with a tiny bit of inline scripting. Add the following to either phase of an inline_script at the start of your experiment, somewhere before your loop:

    # define the starting value
    exp.set("my_var", 0)
    

    Then, in your loop, manipulate the variable as you please by pasting the following in an inline_script's Run phase:

    # get current state
    current = exp.get("my_var")
    
    # do some adjustment here, e.g.
    if exp.get("correct"):
        current += 1
    else:
        current -= 1
    
    # then set the variable again, which updates it to the OpenSesame environment
    exp.set("my_var", current)
    
  • Hi, I have a similar problem. Depending on a value in a question asked before the actual loop I want to run different versions of an experiment. I used the above code to set my variable and update it and it is shown in the variable editor/overview with chosen values, yet I am told that this variable does not exist and the experiments stops. I place one inline script right at the beginning to set the variable and one right after the question were people give the answer upon which the experimental version is decided. I uploaded the experiment and would appreciate any hints - best Miriam


  • Fixed it by adding a missing letter - sorry. Now everything is perfect

Sign In or Register to comment.