[solved] Go from one loop to another
Hi,
I'm new to OpenSesame, so sorry if this is a silly question.
I'm trying to navigate between certain loops. The idea is that a user can score points by answering questions right: if the user has enough points, he or she goes to the next level (which is in a different loop). However, when a person answers questions in the next level wrong, the user goes back to the previous level. I've tried the following things:
This is the inline script in the first loop:
current = exp.get("glob_var")
if self.get('correct_question_response') == 0:
if current > 0:
current=current-1
else:
current = current +1
exp.set("glob_var", current)
if current < 4:
exp.items['experimentloop'].prepare()
exp.items['experimentloop'].run()
which works fine. It goes to the next loop when needed. In the next loop, I have the following inline script:
current = exp.get("glob_var")
if self.get('correct_question_response') == 0:
if current > 0:
current=current-1
else:
current = current +1
exp.set("glob_var", current)
if current < 4:
exp.items['experimentloop'].prepare()
exp.items['experimentloop'].run()
When the total of points is lower than four, it does go back to the first loop, however, when the points total is high enough again, you never get back to the second loop again... It just stops.
I've tried adding this to only the first inline script:
if current > 3:
exp.items['experimentloop2'].prepare()
exp.items['experimentloop2'].run()
and then it does go back, but then it keeps repeating the second loop infinitely, even though it's only supposed to run once... I thought inline scripts in a loop applied only to that particular loop, am I wrong?
I hope I made myself clear!
Comments
Hi Floor,
That's an interesting problem. Your code is already quite good.
However, what's missing at the moment is a stop criterion. When do you want the experiment to terminate? Once we have established that, we can see how this can be implemented in your experiment. So what are the exact rules of your experiment?
Also, it would be helpful if you post the full script of your experiment, for example to http://pastebin.com/.
Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi Sebastiaan,
Thank you for your answer! Let's say, the experiment has to stop once current == 8. Is there some way to put that in an inline script in the loop?
Thanks,
Floor
Hi Floor,
I think you could make your experiment a bit simpler. Let's assume that you have two
sequence
s, called level1 and level2, which implement your two categories of questions. The logic is, if I understand correctly, that you want to run level1 whenglob_var
is less than 4, and level2 whenglob_var
is greater than or equal to 4. Whenglob_var
is 8 you want to break the loop. I think you could implement this purely with conditional statements:The repeat value of the loop is set really high so that it's practically infinite.
That should do the trick, right?
Cheers,
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi Sebastiaan,
yes, thank you for your help! Problem solved