OS (e.g. Win10): Win11 PsychoPy version (e.g. 1.84.x): 2024.2.4 Standard Standalone? (y/n) y What are you trying to achieve?: In the experiment I am trying to build the participants are shown letter sequences which they have to replicate correctly in a text box. If the answer is correct, they should move on to the next sequence. If the answer is incorrect, the same sequence should be shown and replicated again.
What did you try to make it work?:
I added two loops - one to repeat the whole process for every sequence and one that should repeat single incorrectly replicated sequences.
# Initialisiere den Zähler für die Wiederholungen der inneren Schleife
wdh_falsch_counter = 0
# Überprüfe die Eingabe
if input == sequence:
# Wenn die Eingabe korrekt ist:
continueRoutine = False # Beende die aktuelle Routine und fahre mit der äußeren Schleife fort
if input != sequence:
# Wenn die Eingabe falsch ist:
wdh_falsch_counter += 1 # Erhöhe den Zähler für fehlerhafte Versuche
if wdh_falsch_counter < 2:
continueRoutine = True # Wiederhole die innere Schleife
else:
continueRoutine = False # Beende die innere Schleife und fahre mit der äußeren Schleife fort
if wdh_falsch.finished:
continueRoutine = False
What specifically went wrong when you tried that?:
The sequences I replicated correctly were repeated (via inner loop “wdh_falsch”) although a correct answer should lead to showing the next sequence. I have no coding skills or knowledge in Python whatsoever so I am hoping any of you can see possible mistakes/solutions.
Thanks a lot!
You say that this code is in Begin Routine. If the input editable textbox is in that routine then this code needs to be in End Routine.
I think you are also misunderstanding continueRoutine.
continueRoutine = False is usually used in Each Frame code to signal the end of a routine if a certain condition is met and in Begin Routine to skip a routine that hasn’t yet started (though this latter use should now be replaced by ski if in Routine Settings.
loopName.finished = True is generallly used in End Routine to end a loop early.
Hi, first of all thank you for helping me!
The code I posted isn´t in the same routine as the textbox, it´s in my “feedback” routine. When I added it to the “input_sequence” routine (where the editable textbox is) the way you suggested, I got following error message: “feedback_text.setText(thisFeedback)
UnboundLocalError: local variable ‘thisFeedback’ referenced before assignment”. Before, I disabled my feedback-routine and placed a text component (with $thisFeedback) in the “input_sequence” routine.
Then I put the code back into the feedback-routine (in Begin Routine) which caused the same error as in the beginning: I correctly replicated a sequence in the editable textbox but this sequence was repeated two times afterwards (although a correct input should lead to a new sequence).
As far as I know, this is the full error message “text=thisFeedback,
UnboundLocalError: local variable ‘thisFeedback’ referenced before assignment. ioHub Server Process Completed With Code: 0
################# Experiment ended with exit code 1 [pid:5428] #################”
This error doesn´t occur when I disable the feedback components in the input_sequence routine and put them back into the feedback-routine, where I had them originally. Is there any disadvantage in having the code and text component for the feedback in an additional routine?
Unfortunately I still have the problem that the number of repititions per sequence doesn‘t respond to whether my input is correct or incorrect. Instead, each sequence is repeated once after the input. But incorrect input should lead to repeating the same sequence (up to two times) and correct input should lead to the next sequence. I tried getting directions on this by ChatGPT but that only brought up more errors🥲
My code should break out of the inner loop and progress to the next iteration of the outer loop after two incorrect answers. If you also want it to move on after a correct answer you could try: