Loop counter variable - Opensesame
in OpenSesame
Hi everyone,
I have a loop and a sequence inside with several sketchpads.
I want to skip some of the sketchpads in the first trial of the loop.
Do we have a variable as the "loop counter" so I can use it in the sequence "Run if" column?
I want to say "Run if the loop counter is not one!" (so I can skip this sketchpad in the first trial and then have it in the rest).
Thanks in advance,
Kian
Comments
Hi Kian,
Assuming you have an experimental loop with a sequence called "trial_sequence", you should have an OpenSesame variable called "count_trial_sequence" which keeps track of the current trial sequence iteration. Note that the counter starts at 0.
You can set whether or not a script runs through the controls by going to the sequence and setting the “Run if” field:
[count_trial_sequence] > 0
Alternatively, you can also edit it through the script using (don’t forget to hit “Apply and close”). In this example, sketchpad_1 always runs and sketchpad_2 only runs after the first trial:
run sketchpad_1 always
run sketchpad_2 "[count_new_sequence] > 0"
For slightly more complex conditions, it is easier to use Python. You can use Python in an OpenSesame script by starting the condition with an equals sign and access OpenSesame variables using exp.get(). For example, to only run a script during the first and third trial:
=exp.get('count_new_sequence') in (0, 2)
Or in the Opensesame script like:
run sketchpad_1 "=exp.get('count_new_sequence') in (0, 2)"
For more info on OpenSesame variables and using them, see: https://osdoc.cogsci.nl/2.9.3/usage/variables-and-conditional-statements/
Hope this helps,
Thank you very much @Dion.
Very helpful :)