If this template helps then use it. If not then just delete and start from scratch.
OS (Win10):
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.
OBJECTIVE
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).
PROBLEM
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():
import psychopy
from psychopy import core, visual, event
Set up the experiment
win = visual.Window([800, 600], color=âwhiteâ)
Set up the text stimulus
text = visual.TextStim(win, text=âPUT MY TEXT HEREâ, height=0.5, font=âArialâ, color=âblackâ)
Set the words per minute speed
words_per_minute = 185
Set the lines per screen
lines_per_screen = 24
Calculate the time per line
time_per_line = 60.0 / (words_per_minute * lines_per_screen)
Set up the pause time
pause_time = 2.0
Split the text into lines
lines = text.text.split(â\nâ)
Set the current line to 0
current_line = 0
While there are still lines to display
while current_line < len(lines):
# Display the current line
text.text = lines[current_line]
text.draw()
# 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)
Wait for a key press
event.wait_keys()
Close the window
win.close()
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.
Kendal