Shuffle objects

Hi guys,

I am trying an experiment in Psychopy for randomising the posisitton of some object in one image.

I have the codes.

I am using a code component at the begin experiment tab:

import random, xlrd

#randomize seed
random.seed()
 
#input file
in_file = 'MyFile.xlsx'

#number of items to load
num_items = 8

#counters to hold the next stimulus reference
cur_image = 0
cur_position = 0

at the begin routine:

#open the excel file
inbook = xlrd.open_workbook(in_file)
insheet = inbook.sheet_by_index(0)

#arrays to hold our stimuli
image_stim = []
position_stim = []

#loop through the rows in the stimulus file
for rowx in range(1, num_items+1):
    
    #reed in an entire row
    row= insheet.row_values(rowx)
    
    #save the images and positions
    image_stim.push(row[0])
    position_stim.push(row[1])
   
#randomly shuffle the images
random.shuffle(image_stim)

#randomly shuffle the colors
random.shuffle(position_stim)

I have an Excel file which contains everything else for the position.

The problem that I have is in the initialisation of the imports: Alert 4210:JavaScript Syntax Error in ‘Begin JS Experiment’ tab. See ‘Line 1: Unexpected token’ in the ‘Begin JS Experiment’ tab.
For further info see 4210: Probable syntax error detected in your JavaScript code — PsychoPy v2021.2.4

I tried everything that I found in the forum and other forums nothing works. Even the new version with the codes but I still get the same error. Any help would be appreciated.

Hello Amra_Feta,

do you build your experiment with the Builder of PsychoPy or with the Coder of PsychoPy. It looks like your are mixing the two approaches to build an experiment in PsychoPy.
There is, for instance, no need to load libraries when using the Builder. It should be avoided if you want to run the experiment online. The Builder adds libraries which are compatible for online use. random is among them.
Also, you seem to need two independent randomization, one for image_stim, the othe for position_stim. You might want to take a look here.

Best wishes Jens

Hello Jens,

Thank you for your clarification I am trying some things out it seems like its working. Yes i seperated the images and the positions but there are still some small errors. If i need something i will let you know.

Kind regards