Add code to PsycoPy script to display a word story at 185wpm

15 views Asked by At

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.

0

There are 0 answers