psychopy.org | Reference | Downloads | Github

How to call variable from Excel file in code component?

I have a variable (“opacity”) in my conditions Excel file I want to call in a JavaScript code component - e.g. if (opacity === 1): do this. However, it seems PsychoPy isn’t able to access this variable in a code component. What can I do to make this work?

Try changing the name of the variable, just in case opacity is already being used by PsychoPy

The other possibility is that it is coming in as a string rather than a digit.

Best wishes,

Wakefield

I’ve changed the name to a unique variable, and the values under it are just 1s and 0s. What would be the standard way of calling a variable from an Excel file? I tried doing this, but it didn’t work:

conds = new TrialHandler({
        psychoJS: psychoJS,
        nReps: 1, method: TrialHandler.Method.SEQUENTIAL,
        extraInfo: expInfo, originPath: undefined,
        trialList: 'counterbalancing2.xlsx',
        seed: undefined, name: 'conds'
    });

condList = conds.getTrialList()

Personally I’ve only ever used PsychoPy Builder loops to access Excel files so I’m afraid I can’t help.

Are you getting an error message (either from Pavlovia or a console) you can give us?

So basically the code I have is what I posted above, and to call the variable I have this:

if (condList[0]['mem_opacity']){
  foil = num[4];
}

The error I get on Pavlovia when I try to pilot:

Hi,
I use this in the code component to call variable from the Excel file:

thisTrial['variablename'] == 'condition'

In your case, it should be:

if thisTrial['opacity'] == 1:
    do this

If it’s not working, maybe try change 1 to string in the Excel file and try:

if thisTrial['opacity'] == '1':
    do this