Choosing Condition File based on Participant's Number

Version: 2021.1.2
OS: Windows 10

URL - Learning_1 [PsychoPy]

*The code is set to piloting so I don’t know if the link will expire.

Description of the problem: I am trying to convert this string from Python into Javascript. The string chooses to use one of two condition files based on whether a participant’s number is even or odd. (Odd - List 1, Even - List 2). Below is the string in Python which works in the Coder.

trialList=data.importConditions(u’Practice_List’ + str((int(expInfo[‘participant’]) % 2 * -1)+ 2) +’.xlsx’),

And here is Psychopy’s translation into Javascript. I got this from putting the string in the custom code in the Builder.

trialList: importConditions(((“Practice_List” + (((Number.parseInt(expInfo[“participant”]) % 2) * (- 1)) + 2).toString()) + “.xlsx”));,

After inserting the string into the JS code and pushing it to Pavlovia, the code will only pick from condition list 1. Does anyone know what is wrong with it? Or have a simpler way of having the code choose?

Many thanks for any help!

For just two alternatives I would try if / else and remove the variable code from the import statements themselves

Hi @wakecarter

Thank you for your response. This is what I have come up with but I am stuck getting an error.

set up handler to look after randomisation of conditions etc

word_loop = data.TrialHandler(nReps=1, method=‘sequential’,
extraInfo=expInfo, originPath=-1,
trialList= data.importConditions
if(int(expInfo[‘participant’]) %2 == 0)
(‘Practice_List1.xlsx’)
else
(‘Practice_List2.xlsx’),
seed=None, name=‘word_loop’)

The code produces the following error: " TypeError: ‘bool’ object is not callable". Do you know what this means and how to fix it?

Thanks

Full error message: line 744, in
(‘Practice_List1.xlsx’)
TypeError: ‘bool’ object is not callable

That probable means you can’t call an if statement in the middle of defining a TrialHandler. Define a variable first and then use it.