Howdy, Stranger!

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

Supported by

[solved] set a global loop_variable

edited February 2014 in OpenSesame

Hello,

i would like to use an inline_script in a loop_sequence and set variables in the inline_script to be written into the log_file, i.e.

exp.set("stimuli",stimuli[number])

The variable [number] is set in the loop and can`t be used in the inline_script because it is Opensesame_Code and not global (am i right?).

Is there any way to use [number] in an inline_script?

Thanks a lot,

Ben

Comments

  • Hi Ben,

    You cannot use the square-bracket syntax when using Python code. Instead, you should use self.get() to retrieve an in-the-GUI defined variable in an inline_script. So:

    # Retrieve the variable 'number', which is set in a loop item:
    # Thus: FROM GUI/OpenSesame code TO Python code:
    number = self.get("number")
    
    # Set the variable 'stimuli'.
    # Thus: FROM Python code TO GUI/OpenSesame code:
    exp.set("stimuli", number) # or whatever value you want to give to the variable.
    

    See also:

    Cheers,

    Lotje

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

  • edited February 2014

    thank you so much! now everthing works fine!

    in combination with self.log i was able to write all variables in into the log:

    self.log('%s;%s;%s' % (self.get('var1'),self.get('var2'),self.get('var3')))
    

    thanks a lot again!

Sign In or Register to comment.