Showing images based on Slider response - working locally but not on Pavlovia

I am creating a modified version of the BART (balloon/risk task) demo where there are two different colored balloons that earn credit towards two different gift cards (coffee and food/control).

The task begins with a preference assessment so they can choose which gift cards they want. The first routine has two sliders, for Starbucks and Dunkin, and the second is the same but for Subway and Domino’s. This is how I pulled the ratings in “end routine”:

starbucksRating = starbucksSlider.getRating()
dunkinRating = dunkinSlider.getRating()

dominosRating = dominosSlider.getRating()
subwayRating = subwaySlider.getRating()

During the main BART trial, the logo for the restaurants they chose will appear on either side of the screen based on their slider ratings and the current balloon. This works perfectly fine when running locally. Here’s the python code in “begin routine”:

#which caf reward did they choose?
if starbucksRating > dunkinRating:
    cafChoice = 'resources/starbucks.png'
else:
    cafChoice = 'resources/dunkin.png'

#show caf logo for blue balloon only
if is_caff == True:
    cafLogo = cafChoice
else:
    cafLogo = 'resources/blank.png'

#which cont reward did they choose?
if dominosRating > subwayRating:
    contChoice = 'resources/dominos.png'
else:
    contChoice = 'resources/subway.png'

#show cont logo for orange balloon only
if is_caff == False:
    contLogo = contChoice
else:
    contLogo = 'resources/blank.png'

There are two image components named “cafLogoImage” and “contLogoImage” set to “$cafLogo” and “$contLogo” displayed on either side of the screen. “blank.png” is an empty transparent image to essentially make the logo disappear when it isn’t relevant.

…and here is the JS code that was automatically translated:

if ((starbucksRating > dunkinRating)) {
    cafChoice = "resources/starbucks.png";
} else {
    cafChoice = "resources/dunkin.png";
}
if ((is_caff === true)) {
    cafLogo = cafChoice;
} else {
    cafLogo = "resources/blank.png";
}
if ((dominosRating > subwayRating)) {
    contChoice = "resources/dominos.png";
} else {
    contChoice = "resources/subway.png";
}
if ((is_caff === false)) {
    contLogo = contChoice;
} else {
    contLogo = "resources/blank.png";
}

When I try to run this on Pavlovia, the experiment runs fine until it gets to the main trial, giving this error message:

Unfortunately we encountered the following error:

  • when setting the image of ImageStim: cafLogoImage
  • when getting the value of resource: resources/blank.png
  • unknown resource

The project’s git page: Sign in · GitLab

And a snapshot of my builder view:

TIA for any help (: this project is my very first attempt at Python or JS & I’m honestly astonished I’ve gotten this far writing this part up from scratch by myself.

Hello Nicole,

the error message tells you that Pavlovia is looking for the file “blank.png” in the folder “resources”. Is “blank.png” in “resources” of your repository?

Best wishes Jens

Yes, this is my resources folder

Hello

in your if-else construction there is no

but only a cafLogo. Dou you set cafLogoImage somewhere else?

Best wishes Jens

Thank you for the suggestions!

cafLogoImage is the name of the image component (see the builder view screenshot) so I didn’t think they needed to be ‘set’ in code (I could be wrong). cafLogo is the variable that I use within cafLogoImage (same with the cont_ variation for all of this)

I tried changing cafLogo to cafLogoImage in the code to see what would happen and I got this error when running locally:

cafLogoImage.setImage(cafLogoImage)
AttributeError: 'str' object has no attribute 'setImage'

I think it’s mad at me for using the same label twice

Hello Nicole

well, it is not so easy to grasp another person’s experiment. What do you mean with

?

The syntax would be

cafLogoImage.setImage(cafLogo)

So, that was correct. Often forgotten, cafLogoImage is not set to constant?

Best wishes Jens

Thanks again - it is set to ‘set every repeat’

Solution found here!!! Unknown resources when setting the image of ImageStim - #2 by Lu_Leng

Really silly but I had no idea the ‘resources’ box in the PsychoPy settings existed (: