Problem of conditional execution of coroutine components
Hi guys,
I have created variables that contain parameters used to control some aspects of the execution of the program. Those variables are used in conditional statements of sequence elements and they work fine, except when I try to use them INSIDE of coroutines. Then they behave in a strange way.
When a variable is just defined in the inline script that contains the variable assignments at the beginning of the program, and assigned a certain value, but not used in the program, it appears in the list of variables with the correct value. But when I try to use that variable inside of a coroutine as a condition of execution of a component of that coroutine (execution or not of a sound), I get an error message stating that that variable does not exist, although it still appears in the list of variables, but with no value.
That variable is global, how is it that it cannot be used in coroutines and generate a fake error ? Is there a specific way to create variables to be used for conditional control of coroutine components ?
Thank you in advance for your help,
Gérard
Comments
Hi @gerhono ,
For
coroutines, the run-if statement is evaluated during the prepare phase (which I appreciate is a bit counter-intuitive and should be documented better). I'm guessing that you are defining the variable in the run phase of an item that lives at the same level as thecoroutines, and hence the variable isn't defined yet at the moment that the prepare phase of thecoroutinesis executed. Does that make sense? If possible, defining the variable in the prepare phase of theinline_scriptmight solve the issue, although of course this depends on the details of the experiment.— Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Thank you Sebastiaan,
You are right, it works now.
I am used to initialize the variables that will be used through the whole program in an inline script at the top of the program. And it is useful for me to keep all those variables together (and not dispatch them between 'prepare' and 'execute') because I modify them at each run of the program. Would you confirm that, as a general rule, in this kind of setup, all the variables could be initialized in the prepare section ? Are there exceptions ? I ask the question because I remember that in previous programs, I had to move some variables to 'prepare' or 'execute' empirically (without understanding why).
In the program that I am working on at the moment, I have moved all the variables to the 'prepare' section and it works fine. The variable that is used in the coroutine is 'son' :
Thank you very much,
Gérard
Hi @gerhono ,
Would you confirm that, as a general rule, in this kind of setup, all the variables could be initialized in the prepare section ? Are there exceptions ?
Yes, as a general rule initialization should be in the prepare phase. There are certainly exception, but exceptions being by definition unique cases I cannot give you a general rule for those!
— Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!