Randomizing trials name error

I am attempting to randomize 16 conditions in my excel file across 64 faces in my excel file. the 16 conditions take up two rows in the excel file, so I am randomizing two lists of stimuli labelled SelfGain and Charitygain. I used the code from this video but adjusted it for my experiment: Using Code to Randomize Two Lists of Stimuli within a Single Loop -- PsychoPy Mini Tutorials - YouTube

I keep encountering the same error in my code over and over again:
textSelfGain.setText(SelfGain[Cur_Self]
NameError: name ‘Cur_Self’ is not defined

This happens with all the variables. I am not sure how to fix this.

Where does Cur_Self come from?

Hi!

Thanks for your reply. I actually ended up figuring this out. I am wondering, do you have any idea how to randomize 16 trials across an excel sheet that has 64 conditons, so that each of the 16 conditions only appears 4 times?

Have a look at my independent randomisation online demo.

When I try to use the demo you have i get this error:

TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType

Do you mean when you try your own copy of it? It works when I try it here: independent-randomisation [PsychoPy]

Please could you check the error in the console to find out which variable is NoneType?

nope sorry, when i use it in my own study; this is the full error

listA.append(str(int(SelfGain)))
TypeError: int() argument must be a string, a bytes-like object or a number, not ‘NoneType’

Experiment ended.

So the problem is with SelfGain. Where does that come from?

SelfGain and Charitygain are the two lists of stimuli that I am trying to randomize. Together they make up 16 conditions, that I want to repeat 4 times across 64 faces in a random order.

Are you using 0:16 to select the correct rows?

Dollars confuse PsychoPy. I would remove them from the spreadsheet and add them to the display text directly.

(or put the contents of those cells in quotes)

yup i selected 0:16

the dollars aren’t in my spreadsheet that’s actually in my experiment because they weren’t showing up on the display anyways.

If that’s not the spreadsheet you’re using then please could you upload the one you are?

Face stimuli list Giving choices study.xlsx (16.1 KB)

That looks fine (apart from the cursor being in an empty cell but I think that should be okay in this instance).

What tab is your code in?

I would add print(“SelfGain”,SelfGain) just above the error to see what value is shown in the developer console.

I have it in begin routine, the same way that it’s shown in your demo. Not exactly sure where to type in the print(“SelfGain”,SelfGain), the runner shows the error and doesn’t let me type anything.

The print statement goes in Begin Routine, just above listA.append. If you get an error on the JS side, try retyping the quotes.


This is what I got

That’s really useful. It means that most of the cells are working. I still think it’s picking up the wrong rows. You could load them sequentially and then shuffle the list afterwards or you could split those columns into a new spreadsheet.

The easiest first test would be just to turn off the randomisation of the loop (and double check the contents of “selected rows”).

It might be that you need to have a value in row 18 even though you aren’t going to use it – maybe put a dummy value like 999.

When I do it sequentially the transfers load onto the screen, but when i select random there are no numbers presented even when i add a dummy value. Even though the cells are working they aren’t being presented on the screen when its presented at random.