OS (Winows10): PsychoPy version (v2022.2.5):
**Standard Standalone? (y)
**What are you trying to achieve?:
I am new to PsychoPy and have set up an experiment where participants have to evaluate a movie and provide a short review of a specific length. I would like to dynamically display the number of words the participant has already written, and only allow them to continue to the next routine (i.e., click on the NEXT button), if this criterion has been met. I however do not even manage to make the continuation of the routine dependen on participants having entered a specific number of words in the textbox.
So far I have tried:
In End Routine and Each Routine :
if len(textbox.text.split()) > 100:
continueRoutine = true
I also tried to make the Stop of the textbox dependent on the following condition: len(textbox.text.split()) > 100
Any help is very much appreciated. I am also still looking for a good tutorial on how to use builder with code. So if you can hint at any resource that you found helpful this would also be much appreciated.
Hello, welcome to the forum!
You actually want to change continueRoutine = true to continueRoutine = False. Because you don’t want to continue the routine, you want to stop it. Also, boolean should always be capitalized.
Here’s a working example of what you are trying to achieve, including a warning message when the participant presses the submit button before writing more than the required words:
# Start of routine
numberOfWords = 0
showWarning = False
# Each Frame:
numberOfWords = len(textbox.text.split()) # Updating the number of words
text.text = numberOfWords # Setting a text following the numberOfWords
if mouse.isPressedIn(nextButton): # If the participant presses the `next` button
if numberOfWords > 5: # and the numberOfWords is bigger than 5
continueRoutine = False # Continue to the next routine
showWarning = True # Otherwise, show a warning message
thanks so much for your response. Not quite, I first changed
<text.text = numberOfWords> to <textbox.text = numberOfWords>
then the programme runs. However, the text is not displayed when typing, nor does the warning work. I was also wondering where you’d define the warning (I assume you’d have to do this in the Begin of Routine section?). Also, I can just click the nextButton without typing anything.
I used an indefinite amount of time for all components - not sure if that is the mistake.
You shouldn’t change textbox.text = numberOfWords, you set your textbox to numberOfWords each frame. So whenever the participant types anything, it immediately disappears.
the text.text = numberOfWords is there to indicate what is the number of words in the textbox.
The warning is a text component that starts when showWarning is true.
Did you check the example I sent in the previous comment? It should clear everything out. You should also disable the end routine on click in your button.
Everything is in the example, please take a look