Howdy, Stranger!

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

Supported by

[solved] Variable defined using "exp.set" in a for-loop in inline script is not detected by logger

edited June 2015 in OpenSesame

Hi,

In a python inline script, I define experimental variables both inside and outside a for-loop:

exp.set('standard_dur', 4000)
for i in range(1,8):
---exp.set('comp_dur_' + str(i), 2000+i*500)

The variable "standard_dur" is detected by the logger, but not the "comp_dur_X" variables. I read in the forum that the logger detects all variables that are present the first time the logger is run. I can imagine that the "comp_dur_X" variables are not detected because they are only created once the loop is executed. When I initialize the variables with an arbitrary value before running the for-loop, they are properly detected by the logger and the data file contains the values that I assigned to the variables in the for-loop. However, this does obviously not work if I do not know beforehand how many additional variables I need to create. So my question is how I can add variables to the logger "on the fly", i.e., at the time the variables are created.

Sabine

Comments

  • edited 10:19AM

    Hi Sabine,

    Have you tried adding a custom variable in the logger item? It's on the right side of the screen, i believe you can log all the variables create during the experiment by hand there.

    • Laurent
  • edited 10:19AM

    Hi Laurent,

    The problem is that I do not know beforehand how much variables I want to log, so I cannot add them to the logger manually. Therefore I am searching for a way to add the variables to the logger as they are created. My current way out is that I create a large number of variables with a default value. The logger detects these variables. During the experiment, I then assign the values I want to log to a subset of these variables. The remaining, unused variables keep their default value.
    Still, I was wondering whether there is a more elegant way of logging variables that are created during the experiment (i.e., after the logger is run for the first time).

    Sabine

  • edited 10:19AM

    Hi Sabine,

    Normally the logger should detect all variables set with exp.set; even variables you create in a loop. But it might depend on where in the structure your logger is placed exactly.

    If anything, you can also manually log variables (yes, it's possible to log variables "manually" on the fly), as follows:

       for i in range(1,8):
             exp.set('comp_dur_' + str(i), 2000+i*500)
             self.log('comp_dur_' + str(i) + ' =' + str(2000+i*500))
    

    Cheers,

    Josh

  • edited 10:19AM

    Great, thanks!

Sign In or Register to comment.