Uploading online error

Thank you for your advice. What do these refer to in the document you shared?

targetGap = 20 #min gap between targets
targetJitter = 5 #max variation in gap

My demo code inserts targets every 20-25 trials.

Where do I have to put the excel file with the target file name? Should I create a loop around the first routine of the experiment where all this code will go?

And in that excel file, where i give the path of the image files it should not be from the computer right? It should be the path ‘./stimuli/transparent’ which is based on the experiment folder and not from the actual computer disc right?

I think it’s easiest to put the Excel files in the same folder as the experiment file, unless you have a lot of them. Then you don’t need a path.

The loop appending items to your lists points to this file.

So in the excel file I just put the file name of the jpg file eg. ‘apple.jpg’? with no path?

Yes, you can always add a path in the component or the code if necessary.

Alright thank you so much. I am not very familiar with coding on Python so I can not fully follow the code demos you sent. I tried to understand your demo code so I want to make sure i can use this code to meet the needs of my experiment.

So i have 11 images, and for every participant 3 of these will be allocated as targets and the rest as distractors. But these three targets will change for every participant so every time the experiment run there needs to be a random allocation of targets.

So to do that I used this code:

img_dir = ‘./stimuli/transparent’

get image file path

img_files = [os.path.join(img_dir,i) for i in os.listdir(img_dir) if i.endswith(’.jpg’)]

choice three targets and no target randomly

shuffle(img_files)

0-2 are targets and 3 is no target

expInfo[‘par_targets_list’] = img_files[:4]

from third file onwards: distractor

expInfo[‘distractors’] = img_files[4:]

And then, these three targets will appear with different frequency, such that 1 target will appear 70% of the trials, the other 20% of the trials and the other 10% of the trials. So to do that I used this code:

#targets of 3 prevalence
current_target = “”
if Prevalence==“HP”:
current_target = expInfo[‘par_targets_list’][0]
elif Prevalence==“EP”:
current_target = expInfo[‘par_targets_list’][1]
elif Prevalence==“LP”:
current_target = expInfo[‘par_targets_list’][2]

Prevalence==‘A’/target-absent trial

else:
current_target = expInfo[‘par_targets_list’][3]

(The HP,LP and EP prevalence were taken from an excel file I used)

So I want this to be able to run online. So can you please explain the steps of your demo in relation to this design so I can follow more clearly?

Thank you

img_files.append(Image)
in a loop pointing at a spreadsheet with a column called Image

You’ll need to put img_files-=[] in Begin Experiment

the loop should only contain 1 nReps?

Yes for the loop pointing at the spreadsheet

I had the following code part in the Begin Experiment point. is that correct or should i put that in the Before Experiment point?

img_dir = ‘./stimuli/transparent’

get image file path

img_files.append(Image)

choice three targets and no target randomly

shuffle(img_files)

0-2 are targets and 3 is no target

expInfo[‘par_targets_list’] = img_files[:4]

from third file onwards: distractor

expInfo[‘distractors’] = img_files[4:]

These have to come after the code in the loop, therefore Begin Routine not Begin Experiment

I did it in that way and it is working okay when I run it on my pc but now I receive this error when I try to run it online:

  • TypeError: img_files.append is not a function. (In ‘img_files.append(Image1)’, ‘img_files.append’ is undefined)

It seems like it does not recognise the append function

You need to define append in Begin Experiment. Look at the top of my code snippets page or my 2020 crib sheet for the code.

thisExp=psychoJS.experiment;

win=psychoJS.window;
event=psychoJS.eventManager;
shuffle = util.shuffle;
Array.prototype.append = [].push;

You mean i should add these in the first routine as JS and not Auto->JS right?

Yes

When I do that and run the experiment on my pc I get this error:

thisExp=psychoJS.experiment;
NameError: name ‘psychoJS’ is not defined

Should i also define psychoJS separately?

If you ran it locally then that command wouldn’t have been read if you’d put it in a JS only code component

Isn’t this how it should be done?

Correct. Please could you show a screenshot of your error message? How are you trying to run it?