Problems with slider in psychopy builder

Hi, I am trying to run a pilot study via psychopy builder. Basically, I want participants to choose the last frame of the video they saw before using a slider. That is to day, based on their response, the corresponding pictures should update in real-time. The pictures’ format is something like butter_melt0011.jpg. My codes are like this:

def pad_with_zeros(number, width):
    num_str = str(number)
    padding = width - len(num_str)
    return '0' * padding + num_str


slider_choice = slider.getRating()

if slider_choice == None:
    slider_choice= 120    
print(slider_choice)
num_str = pad_with_zeros(slider_choice, 4)

thisImage = 'stimuli/jpg_frames/'+thisTrial['ImagePath']+'/'+thisTrial['ImagePath']+num_str+'.jpg'

I got the error saying couldn’t find the image, and I guess because slider.getRating() returns None, but not the number. What other code should I put here? Should I also include a mouse component to record participants’ response?

Any help is greatly appreciated.

Hello,

We cannot determine what is in the if construction because you have not enclosed the code in triple `. So it is not properly formatted.

Use a print command to print the value of thisImage.

Best wishes Jens

Hi Jens,

Thanks for the reply.
That is the code on code component in psychopy builder. Basically, thisImage is for the image component to find the corresponding image that participants choose depending on their rating.

I’ve edited your post to show the code.

@JensBoelte suggested that you add a line print(thisImage) to see whether the issue is with the filename.

Since this is online then the issue may be simply that you haven’t added the images in Experiment Settings/Online/Additional Resources. Showing the error message would help with checking this.

Does it work locally?

If you have too many possible frames to want to load them all into memory at the start of the experiment then you may need to use a code component (prepareResources) or a Resource Manager component to load them while the participant is reading the instructions.

Hi,
Thanks for the help. I added print(thisImage) but nothing shows up. My whole procedure is that participants watch a animation and hear a sentence with a cross on the screen, then they move the slider. I tested it locally but not online via Pavlovia yet. It doesn’t work locally. Can I have more information about the prepareResources?

Hello

the ResourceManager is not needed for offline experiments. You find information about resources in online studies here Resources in online studies — PsychoPy v2023.2.3.

What is the value of print(thisImage)? Does has the intended value (filename)?

Where and how do set thisImage Do you use an image-component set to set every frame?

Best wishes Jens