Howdy, Stranger!

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

Supported by

[solved] Setting global variables

edited December 2011 in OpenSesame

Hello everyone!! I'm trying to set global variables in a dummy experiment using an inline script. But I'm getting execution errors when I try to run the experiment.

This is the code:


foo = 1
self.experiment.set("foo_var", foo)

Then, when I try to invoke "foo_var" in a sketchpad, OpenSesame shows me a execution error, like this:

Error: Runtime error
Description: Variable 'foo_var' is not set in item 'sketchpad'.

You are trying to use a variable that does not exist. Make sure that you have spelled and capitalized the variable name correctly. You may wish to use the variable inspector (Control + I) to find the intended variable.

Any suggestions?

Thanks in advance!!

EDIT: Solved... I was using a sketchpad instead of a feedback item... Sorry :P

Comments

  • edited December 2011

    Good to hear that you worked it out!

    Because of the two phases (prepare and run) it can be a bit confusing when a variable is available. The basic idea is simple: The prepare routine of each item in a sequence is called before the run routine.

    • A sketchpad canvas is constructed during the prepare phase. Therefore, if you have an inline script that sets a variable in the run phase (ie., after the prepare phase), it will not be available in the sketchpad. However, if you set the variable in the prepare phase of the inline script, you can use it in the sketchpad

    • A feedback canvas is constructed during the run phase. Therefore, you will be able to use all variables, regardless of whether they have been set in the prepare or in the run phase. (Provided, of course, that the inline script appears before the feedback in the order of the sequence.)

    More info:
    http://osdoc.cogsci.nl/usage/giving-feedback-to-participants

Sign In or Register to comment.