How to reference excel column content in JAVA "if" script

Hello:)
I’m new to PsychoPy and have close to zero knowledge about coding.

What are you trying to achieve?:
In my experiment I would like to skip some routines when a certain excel cell in my trial sheet contains an “XXXXX”, using an “if” JAVA script.
I couldn’t figure out how to direct the script to read the desired excel column.

What did you try to make it work?:
Tryin to avoid referencing the excel column directly from the script, I added a text component that accesses this column and displays its text (for 0s). Then I tried to reference the text component using this code:

if (text_12 === “XXXXX”) {
continueRoutine = false;
}

*I copied this “if” code from another part of the experiment, where it worked well referencing a keyboard response. It is located in the “each frame” tab in a code component.

I guess it isn’t written correctly because when trying to pilot the experiment on Pavlovia I got the following error message:

  • ReferenceError: XXXXX is not defined

Any help will be greatly appreciated!!

Why are you trying to avoid referencing the Excel column?

I strongly recommend using an Auto component if you are trying to run your experiment online.

Something like

if colName=='XXXXX':
     continueRoutine=False

in Begin Routine or Each Frame

Thank you for your reply!
What is an Auto component?
I tried using your code but Pavlovia keeps showing me the same error message.
How would the program know I’m referencing a name of an excel column in this case? Is every column in my trials sheet already considered a variable automatically or do I need to define it first?

When you create a loop pointing to a spreadsheet every column in that spreadsheet is automatically available as a variable within that loop.

A code component can be Python, JavaScript, Both or Auto translated

That’s great! Do you have any idea why won’t it work then?

I have to assume that you are missing something.

Please could you show screenshots of your code components and how they relate to your components, routines and flow.

I have a number of routines that include this same code component in order to skip them.


Those are the relevant columns in my excel sheet. I also have routines that contain a similar code component for column “CondL”.
image

You are showing me Python code in a JavaScript code component. Please copy the code to the clipboard and then paste it into the Python side on auto components

I just was instructed to use the JS tab specifically, which means I need to use a JS code :\

When you use an auto component then the JS side gets filled in automatically when you paste in Python.

Perhaps you should point the person who instructed you to my crib sheet.

I tried using your code in auto component, and also tried the auto-translated javascript code in JS component, both attempts gave back the same error :confused:

Please could you show a screenshot of your code component now?

Does this look OK?

That looks okay. Is CondF defined in your conditions file and nowhere else

As you can see in a previous screenshot it’s the title of one of my excel columns, but it seems like the problem is consistently with the XXXXX part:


Is there a reason to believe that I need to define the XXXXX string first for JS? It doesn’t make much sense to me to do so…

Use the developer console to identify which line that error is coming from. Are you using XXXXX anywhere else in your experiment?

Are you clearing the Browser cache?

I finally managed to locate my problem, it doesn’t have anything to do with the current code! apparently all the changes I kept making on psychopy didn’t get updated on pavlovia!
Thank you so much for your help dealing with JS!!

Right now I’m seeing a different problem :sweat_smile:
Some of the routines with this code are not getting skipped, and others (using the same code but referencing a different column) lead to displaying “Hello World” instead of skipping. (I’m pretty sure that the “hello world” is showing in place of a these routines that should be skipped).
Needless to say there is no hello world in my sheet, and I searched “hello world” in my code in pavlovia with 0 results.

Please could you show your loop which displays the column name and the code that skips the routine.

Hello world is the default display for missing text


This is my demo trials sheet, just as you said the “hello world” is showing instead of word1 and word2 in items 7 and 8.


This is the code as you guided me to use it. It is used for skipping routines for items 9 and 10, and I have the same code with column “CondL” for skipping different routines for items 7 and 8 (containing the blank word cells). Both routines aren’t skipped when needed to.

Any Idea why it wouldn’t work?

I can’t immediately see any issues. If you are using a recent version then the code should also work in Begin Routine but in Each Frame it should be fine apart from perhaps displaying Hello World briefly.

You should add print(‘CondF’,CondF) just before the if statement and print(‘Skipping now?’) within it to narrow down which bit is failing. Are you doing anything to modify CondF before it gets checked?