psychopy.org | Reference | Downloads | Github

Go to certain loops with Experiment setting info

The study I’m trying to create has 2 sessions to it. In my program it has 3 back to back loops. One of my variable in my experimental settings is “Session”. I want to program it so that when the user types in the number 2 in the “Session” box in the beginning of the experiment, the program will directly jump to and start from the 3rd loop. I’ve tried adding a code component to the beginning of each loop and have this code listed below it. But it doesn’t seem to work. Does anyone know a better idea on how to solve this problem?

(first loop):

if ($expInfo['Session] == 2):
    trials.finished = True

(second loop):

if ($expInfo['Session] == 2):
    trials_1.finished = True

Please always describe exactly what you mean by this.

However, I’m going to guess that what happens is that you get the first trial run in each loop, regardless of which you want to either run completely, or not at all. This is becuiase the .finished attribute only takes effect at the end of an iteration, so if you don’t want anything to happen on a given loop, you also need to tell the routines within to not run. So you need something like this (NB each loop needs to do a different check, so that only one will run):

First loop:

if expInfo['Session'] == 2:
    trials.finished = True
    continueRoutine = False

Second loop:

if expInfo['Session'] == 1:
    trials_1.finished = True
    continueRoutine = False

NB

  • don’t randomly sprinkle $ signs around in code components: it is not valid Python syntax, just something that goes in Builder dialogs to indicate that an expression should be treated as code and not as literal values.
  • be careful to terminate strings with ' at each end.
  • the () are not needed around the test in the if statement.
  • it is possible that the values in the expInfo dictionary don’t come through as numbers, but get treated as strings, in which case you might need to check them with quotes, i.e.
    if expInfo['Session'] == '1':