Type Error when setting Image: reading 'src'

I am experiencing a problem when synching my experiment online: I have an image stimulus in the builder, called ‘Slides’ and this is supposed to be filled with a conditional and randomised slide deck.
In the offline version this is working without problems and also in a previous online version without the slide deck randomisation I had no issues. So I am assuming that this might be related to this new code snippet. Any help would be more than appreciated :sweat_smile:


Loop: Interim
Trial: InitializeInterim
Tab: End Routine

var Cond;
messageType = "interim";
Cond = Math.random(["Gain", "Loss"], {"size": 1});

Loop: interim
Trial: messages
Tab: Begin Routine

key_resp = new core.Keyboard({psychoJS: psychoJS, clock: new util.Clock(), waitForStart: true});

idx = 0;
selectedDeck = [];
if ((messageType === "introduction")) {
    selectedDeck = introSlide;
if ((messageType === "interim" && Cond === "Gain")) {
    selectedDeck = interimSlideGain;
    gainc = 'gain';
if ((messageType === "interim" && Cond === "Loss")) {
    lossc = 'loss';
    selectedDeck = interimSlideLoss;
if ((messageType === "thanks")) {
    selectedDeck = thanksSlide;
thisSlide = selectedDeck[idx];

Each Frame:

theseKeys = key_resp.psychoJS.eventManager.getKeys({"keyList": ["left", "right"]});
if (theseKeys) {
    if (((theseKeys[0] === "left") && (idx > 0))) {
        idx -= 1;
    } else {
        if (((theseKeys[0] === "right") && (idx < (selectedDeck.length - 1)))) {
            idx += 1;
        } else {
            if (((theseKeys[0] === "right") && (idx === (selectedDeck.length - 1)))) {
                continueRoutine = false;
thisSlide = selectedDeck[idx];

The image stimulus refers to a builder component with the name ‘Slides’

Is src one of your spreadsheet columns?

Does it have any blank rows?

What does your image component Slides look like?

Thank you for the response! I am not trying to load the images from a spreadsheet, but they are defined earlier in the experiment:

introSlide = ["resources/1_Intro.png", "resources/2_Intro.png", "resources/3_TrainingInstr.png", "resources/4_TrainingFeedback.png"];
interimSlideGain = ["resources/5_EndTraining.png", "resources/6_InstrPMtask.png", "resources/7a_IncentiveInfoGain.png", "resources/8_CharityInfo.png", "resources/9a_GainContingent.png", "resources/10_DonateOrKeep.png", "resources/11_KeysOverview.png"];
interimSlideLoss = ["resources/5_EndTraining.png", "resources/6_InstrPMtask.png", "resources/7b_IncentiveInfoLoss.png", "resources/8_CharityInfo.png", "resources/9b_LossContingent.png", "resources/10_DonateOrKeep.png", "resources/11_KeysOverview.png"];
thanksSlide = ["resources/12_End.png"];

So the images are .png files from a local folder and they are defined at the beginning of the experiment, as ‘decks’, since they contain the instructions to the experiment. Participants can use the arrow keys to go back and forth between them.
Interestingly, loading images during the introSlide is working perfectly fine, even though the code is the exact same as in the interim > messages > begin routine snippet that I included in the original post above.
So clearly, there is a mistake or something is missing from the math.random function.
The idea is that there is a gain condition, which is meant to show the interimSlideGain slide deck, and a loss condition, in which the interimSlideLoss deck is displayed via the ‘Slides’ variable.

The python code for randomising between the two decks

Cond = np.random.choice(("Gain", "Loss"),size = 1)

is working fine.
But the js translation is clearly not what it is meant to look like :see_no_evil:

Cond = Math.random(["Gain", "Loss"], {"size": 1}); 

I assume Math.random isn’t designed to randomise between strings?


The way I randomise (because I always avoid np.random.choice) is shuffle a list.

For example

Conds = ["Gain", "Loss"]
Cond = Conds[0]

For between participant variables, I would recommend setting a value for group in the VESPR Study Portal and then use that to assign Cond to achieve a more equal number of participants in each group (or Conds[int(expInfo['participant'])%2] if you want to use the free version).

Thank you so much! This worked eventually! :slight_smile:
Have a good weekend!