If this template helps then use it. If not then just delete and start from scratch.
PsychoPy version (2021.2.3)
**Standard Standalone? (y)
Hi PsychoPy Community,
I would be grateful for help with a problem I am having where PsychoPy crashes the experiment whenever I insert a custom code block into my script. I am 100% sure it is due to my lack of coding experience rather than any issues with PsychoPy.
I am using PsychoPy v2021.2.3 which I am aware is an older version, but I need to use this version for one of my studies. However, if I can achieve my objectives with a newer version and can have two versions of psychopy running on a computer then I could entertain this option. Unless the current coded script I have can be fixed. I also need the finished script to ideally interface back with builder until I am more fluent with python coding, since I would potentially be attempting to add eye tracking components and EEG markers into the output data.
The objective is to display a written “Word Story” (Black Arial font on a white screen) one line at a time on the screen at a rate of 185 words per minute until the screen is evenly filled with 24 lines of text. After a short pause of 2s the screen should clear and the story continue filling up the next screen and so on until the entire story has been presented.
Before the story the routine script should start with a Welcome screen (black screen with white text) “Welcome, you are about to read a written story. Press Space to start” – where the space bar will progress the script to the written story.
After the story the end screen should display automatically for 20s when the story ends and read “Thank you for reading, please see the researcher now” – (on a black screen with white text).
I have created a script with the basic flow from WelcomeScreen, Blank500, WordStory, Blank500, and End Screen as a starting point in builder. The full story is coded within the script and defined in the # Initialize components for Routine “WordStory” under the variable “text”. I have already created an audio story and silent picture story with a similar routine setup which work well. It is just the written story presentation I am having trouble building since all attempts to insert a code block for the specifications I need to present the stimuli have failed.
I have attached a github link to the current script “MikeHooter.py” if this helps and could be modified so that it achieves the objective or help me to understand what I should write and insert to have better success with this. https://github.com/KendalJohnson/SharingZone/blob/main/MikeHooter.py
These are the pieces I have been attempting to work with, however I don’t think restricting the screen size is a good idea since I have seen people run into issues with this. I am also unsure of the height. I also don’t think it needs an event.wait_keys():
from psychopy import core, visual, event
win = visual.Window([800, 600], color=“white”)
text = visual.TextStim(win, text=“PUT MY TEXT HERE”, height=0.5, font=“Arial”, color=“black”)
words_per_minute = 185
lines_per_screen = 24
time_per_line = 60.0 / (words_per_minute * lines_per_screen)
pause_time = 2.0
lines = text.text.split(“\n”)
current_line = 0
while current_line < len(lines):
# Display the current line
text.text = lines[current_line]
# Wait for the appropriate time core.wait(time_per_line) # Increment the current line current_line += 1 # Check if the screen is full if current_line % lines_per_screen == 0: # Clear the screen core.flip() # Wait for the pause time core.wait(pause_time)
Many thanks in advance as any help on this is greatly appreciated.
Acknowledgement in my PhD thesis if you can help me solve this not notable, but this is the best I can offer… and the hope that my research may contribute to improvements in early Dementia screening.