Issues and inconsistencies with loading stimuli (i.e., images and text) from .csv loops

URL of experiment:

PsychoPy Version: v.2023.2.3
Description of the problem:

I have an admittedly complex experiment that I have spent months designing in the Builder. I have added my own code to many of the routines (with the AutoJS function turned on – it always seems able to successfully convert). The experiment runs smoothly start to finish on my local computer. However, I’m running into some major issues when it comes to getting it running on Pavlovia :frowning:. The first project, “AAA_0B”, quits immediately after the images have successfully loaded and I press “OK” with the following error:

- Unfortunately we encountered the following error:
    - when setting the image of ImageStim: image_instruct1
    - when getting the value of resource: ./instructions/instruct1.jpg
    - unknown resource
- Try to run the experiment again. If the error persists, contact the experiment designer.

I thought it might be an issue with the way I set the image variable to update based on keypresses which allows subjects to navigate through the instructions at their own pace (see code below). To test this idea, I created a new project which I called “test_noInstruct” with the instructions component and stimuli removed, but everything else constant. The experiment was able to begin and displayed the first page (simple text) without a hitch, but was unable to execute the next routine, a comprehension check, successfully – the question_compcheck1 and task_compcheck1 components presented, but none of the option components (e.g. option1_compcheck1, etc.). Moreover, the background color should be white, not grey.

- Unfortunately we encountered the following error:
    - ReferenceError: None is not defined
- Try to run the experiment again. If the error persists, contact the experiment designer.

I specifically used loops instead of hard coding my routines as the online documentation suggested doing so for both code efficiency as well as for ease of Python->JS conversion. However, I’m sensing that this approach might somehow be stymying the JS translation from working effectively.

Finally, I again created a new experiment, this time without instructions or comprehension check (“test_noInstruct_noComp”). Here, it gets stuck on presenting SOME images (icons that are displayed and change opacity in response to keypresses, stored in the “fig_all/” repo) but not others (my stimuli in “stim_all/”). All stimuli are .jpgs with extensions all in lowercase. The only thing I can think is that they might be too large for Pavlovia to handle, but surely it would then prevent them from loading at the very beginning!

- Unfortunately we encountered the following error:
    - when setting the image of ImageStim: left_practiceEnc1
    - when getting the value of resource: fig_all/resp_natural.jpg
    - unknown resource
- Try to run the experiment again. If the error persists, contact the experiment designer.

I’m new to online experiments and spent the past 2 days tearing my hair out only to realize that I had a folder called “/icons/” (now “fig_all”) which was being ignored due to the .gitignore file which includes Icons?. I also spent an incredibly long time getting the comprehension check working (I’ll note that I had to make some major concessions because even the way it runs now causes PsychoPy to freeze when the experiment ends even successfully due to all of the information it prints to the runner), so I’m really hoping I don’t have to go all the way back to the drawing board for this! Code is below and .csv loop files are attached.

I’m feeling very lost and hoping to receiving some support even just in learning how to appropriately and systematically troubleshoot these kind of conversion issues ESPECIALLY with a complex behavioral experiment. Any help would be greatly appreciated!


Routine: instruct1

Component: code_instruct1
#Begin Experiment

win.mouseVisible = False
N_instruct1 = 1

max_instruct1 = 15
min_instruct1 = 1

#End Routine

if resp_instruct1.keys == 'left':
    N_instruct1 -= 1
elif resp_instruct1.keys == 'right':
    N_instruct1 += 1
elif resp_instruct1.keys == 'space':
    if N_instruct1 == max_instruct1:
        loop_instruct1.finished = True

if N_instruct1 > max_instruct1 :
    N_instruct1 = max_instruct1
if N_instruct1 < min_instruct1 :
    N_instruct1 = min_instruct1

Component: image_instruct1 (sets every repeat, takes the image ./instructions/instruct + str(N_instruct1) + '.jpg')

Component: resp_instruct1 (force ends routine, takes 'left','right','space' keys)

Loop: loop_instruct1 (does not take a .csv file)


Routine: compcheck1

Component: code_compcheck1
#Begin Experiment

nCorrect_compcheck1 = 0
nTrials_compcheck1 = 0

#Begin Routine

msg = "Please answer the above question about the " + task + ".\nUse your arrow keys to toggle between the possible choices.\nPress 'ENTER' or 'RETURN' to submit your response."

# Clear keyboard
event.clearEvents()

# Initialize variables
selected_option_compcheck1 = 1  # Start with the first option selected

# Make all options somewhat opaque at the start
option1_compcheck1.opacity = 0.75
option2_compcheck1.opacity = 0.75
option3_compcheck1.opacity = 0.75
option4_compcheck1.opacity = 0.75

# Initialize 'keys_pressed_compcheck1' variable
thisExp.keys_pressed_compcheck1 = {'up': False, 'down': False}

# Helper function to update opacity
def update_opacity_compcheck1():
    option1_compcheck1.opacity = 1 if selected_option_compcheck1 == 1 else 0.25
    option2_compcheck1.opacity = 1 if selected_option_compcheck1 == 2 else 0.25
    option3_compcheck1.opacity = 1 if selected_option_compcheck1 == 3 else 0.25
    option4_compcheck1.opacity = 1 if selected_option_compcheck1 == 4 else 0.25

#Each Frame

keys_compcheck1 = event.getKeys(keyList=['up', 'down', 'return'])

for key in keys_compcheck1:
    if key == 'up':
        selected_option_compcheck1 = selected_option_compcheck1 - 1 if selected_option_compcheck1 > 1 else 1
        thisExp.keys_pressed_compcheck1['up'] = True
        update_opacity_compcheck1()
    elif key == 'down':
        selected_option_compcheck1 = selected_option_compcheck1 + 1 if selected_option_compcheck1 < 4 else 4
        thisExp.keys_pressed_compcheck1['down'] = True
        update_opacity_compcheck1()
    elif key == 'return':
        # Only end the routine if 'up' or 'down' has been pressed first
        if thisExp.keys_pressed_compcheck1['up'] or thisExp.keys_pressed_compcheck1['down']:
            continueRoutine = False

#End Routine

# Check whether response is correct
resp_compcheck1_corr = (selected_option_compcheck1 == option_corr)
# Update counting variables
nTrials_compcheck1 += 1
if resp_compcheck1_corr:
    nCorrect_compcheck1 +=1
# Calculate accuracy
if nTrials_compcheck1 >= 4:
    acc_compcheck1 = nCorrect_compcheck1/nTrials_compcheck1
    thisExp.addData('acc_compcheck1', acc_compcheck1)
# Save the response data
thisExp.addData('selected_option_compcheck1', selected_option_compcheck1)
thisExp.addData('resp_compcheck1_corr', resp_compcheck1_corr)
thisExp.addData('nCorrect_compcheck1', nCorrect_compcheck1)
thisExp.addData('nTrials_compcheck1', nTrials_compcheck1)
# Reset keys pressed dictionary
thisExp.keys_pressed_compcheck1 = {'up': False, 'down': False}

Component: quiz_compcheck1 (text, takes $quiz from .csv)

Component: option1_compcheck1 (text, takes $option1 from .csv loop)

Component: option1_compcheck2 (text, takes $option2 from .csv loop)

Component: option1_compcheck3 (text, takes $option3 from .csv loop)

Component: option1_compcheck4 (text, takes $option4 from .csv loop)

Component: task_compcheck1 (text, takes $msg)

Component: resp_compcheck1 (keyboard, takes 'up', 'down', 'return')

Loop: loop_compcheck1 (takes “compcheck-1.csv”)

CSV: compcheck-1.csv (2.0 KB)


Routine: practiceEnc1

Component: code_practiceEnc1
#Begin Routine

win.mouseVisible = False
msg1 = "TOO SLOW!"
clr1 = "mistyrose"
clr2 = "darksalmon"
left_practiceEnc1.opacity = 0.5
right_practiceEnc1.opacity = 0.5
if "size" == context:
    left = "fig_all/resp_bigger.jpg"
    wh_L = (0.36, 0.143)
    right = "fig_all/resp_smaller.jpg"
    wh_R = (0.426, 0.143)
    question = "Is this item BIGGER or SMALLER\n than a shoebox?"
elif "kind" == context: 
    left = "fig_all/resp_natural.jpg"
    wh_L = (0.43, 0.143)
    right = "fig_all/resp_manmade.jpg"
    wh_R = (0.486, 0.143)
    question = "Is this item NATURAL or MANMADE?"
event.clearEvents('keyboard')

#Each Frame

if t >= 5.5:
    if 'left' == resp_practiceEnc1.keys:
        left_practiceEnc1.opacity = 1.0
        right_practiceEnc1.opacity = 0.5
        if 'left' == ans_corr:
            msg1 = "GREAT JOB!"
            clr1 = "honeydew"
            clr2 = "darkseagreen"
        elif 'right' == ans_corr:
            msg1 = "Oops – not quite!"
            clr1 = "mistyrose"
            clr2 = "darksalmon"
    elif 'right' == resp_practiceEnc1.keys:
        right_practiceEnc1.opacity = 1.0
        left_practiceEnc1.opacity = 0.5
        if 'right' == ans_corr:
            msg1 = "GREAT JOB!"
            clr1 = "honeydew"
            clr2 = "darkseagreen"
        elif 'left' == ans_corr:
            msg1 = "Oops – not quite!"
            clr1 = "mistyrose"
            clr2 = "darksalmon"

Component: question_practiceEnc1 (question, text in .csv loop file)

Component: item_practiceEnc1 (image, takes $item defined in .csv file, presents stimuli in “stim_all/”)

Component: resp_practiceEnc1 (keyboard, accepts ‘left’ and ‘right’)

Component: left_practiceEnc1 (image, takes $left, variable defined in .csv file)

Component: right_practiceEnc1 (image, takes $right, variable defined in .csv file)

Component: fdbck_practiceEnc1

Loop: loop_practiceEnc1 (takes “practice_enc-1.csv”)

CSV: practice_enc-1.csv (139 Bytes)


In the Experiment Settings, make sure all of the image files that might be presented are in the “additional resources” tab. Nine times out of ten that’s what gives you the “unknown resource” error.