I also have an issue related to this…
In my experiment, participants have to choose an avatar that is later saved as a variable and used throughout the experiment. Since the PsychoPy builder solution does not work online, I have this component of code in begin routine:
// List of image file names
let avatar_files = [“image1.jpg”, “image2.jpg”, “image3.jpg”, “image4.jpg”];
// Positions for the 4 avatars
let positions = [[-0.3, 0.3], [0.3, 0.3], [-0.3, -0.3], [0.3, -0.3]];
// Shuffle positions so they appear randomly
util.shuffle(positions);
// Assign images to components in order
avatar1.setImage(avatar_files[0]);
avatar2.setImage(avatar_files[1]);
avatar3.setImage(avatar_files[2]);
avatar4.setImage(avatar_files[3]);
// Assign random positions to each
avatar1.setPos(positions[0]);
avatar2.setPos(positions[1]);
avatar3.setPos(positions[2]);
avatar4.setPos(positions[3]);
// Variables to store later
let chosen_avatar = null;
let opponent_avatars = null;
And this in end routine:
// Check for mouse clicks
let mouse_clicks = mouse.getPressed();
if (mouse_clicks[0]) { // Left button clicked
let avatars = [avatar1, avatar2, avatar3, avatar4];
for (let i = 0; i < avatars.length; i++) {
if (avatars[i].contains(mouse)) {
// Store chosen avatar
chosen_avatar = avatar_files[i];
// Get remaining avatars
let remaining = avatar_files.filter(f => f !== chosen_avatar);
// Randomly pick 2 opponents
opponent_avatars = util.shuffle(remaining).slice(0, 2);
// Save for later use
expInfo['chosen_avatar'] = chosen_avatar;
expInfo['opponent1'] = opponent_avatars[0];
expInfo['opponent2'] = opponent_avatars[1];
// Store in data file
psychoJS.experiment.addData('chosen_avatar', chosen_avatar);
psychoJS.experiment.addData('opponent1', opponent_avatars[0]);
psychoJS.experiment.addData('opponent2', opponent_avatars[1]);
continueRoutine = false;
break; // stop checking once one avatar is chosen
}
}
}
However, now it does not save anything and it does not end the routine..