UnboundLocalError in line 384 & frozen participant screen

OS: Win 10
Psychopy: v1.5
Error Message: File “D:\separate_components_lastrun.py”, line 384, in run
text_L_C = visual.TextStim(win=win, name=‘text_L_C’,
UnboundLocalError: local variable ‘visual’ referenced before assignment
################# Experiment ended with exit code 1 [pid:9836] #################
Previous attempts: established the visual.textStim earlier in the code (got a syntax error). Tried to just use builder to make the text boxes and ended up with code talking about the visual.textstim.

I don’t know what to do to get this block of the code to work reliably. I was able to see the participant screen once but was not able to use the keyboard arrows to respond to the prompt.
separate_components_lastrun.py (40.9 KB)
separate_components.psyexp (104.9 KB)

You have coder code which should be removed for use in Builder. For example, all Builder experiments automatically import a range of libraries.

# --- Import packages ---
from psychopy import locale_setup
from psychopy import prefs
from psychopy import plugins
plugins.activatePlugins()
prefs.hardware['audioLib'] = 'ptb'
prefs.hardware['audioLatencyMode'] = '3'
from psychopy import sound, gui, visual, core, data, event, logging, clock, colors, layout, hardware
from psychopy.tools import environmenttools
from psychopy.constants import (NOT_STARTED, STARTED, PLAYING, PAUSED,
                                STOPPED, FINISHED, PRESSED, RELEASED, FOREVER, priority)

import numpy as np  # whole numpy lib is available, prepend 'np.'
from numpy import (sin, cos, tan, log, log10, pi, average,
                   sqrt, std, deg2rad, rad2deg, linspace, asarray)
from numpy.random import random, randint, normal, shuffle, choice as randchoice
import os  # handy system and path functions
import sys  # to get file system encoding

import psychopy.iohub as io
from psychopy.hardware import keyboard

You shouldn’t therefore import visual, especially not 33 times (end routine within a loop of 3 repetitions of a spreadsheet with 11 conditions).

Also, PsychoPy will already be running in a window called win so when you execute win = visual.Window() you will break the current window. Are you trying to use two windows?

Here is a thread about how to do that

Thank you so much for sending the thread about it. I’ll look into it asap!