Edited: If statement in PsychoJS

EDIT: the previous title of this post was Clickable_stimuli.clicked_name works in PsychoPy but error in PsychoJS. It was troubleshot to the point that I think the clickable_stimuli.clicked_name is working, but there’s still a problem setting the variable, so it might be something with the if statements.

URL of experiment: Pavlovia

Description of the problem: Locally, I am able to set a conditions file based on a mouse click, but it does not work when pushed to Pavlovia.

here are mouse component basic properties


here are mouse component data properties


here is the variable that is set based on the mouse click and used in conditions file

here is the end routine snippet that should set deckChoice to 1:4 based on click

here is the loop that uses the variable


The error is an “unknown resource: deck_0.csv”


what have I tried?

I tried to modify the JS code manually in the end routine code snippet: tried removing , tried == instead of ===, tried removing quotations

edit: in replies below, I printed both variables to the console in Firefox. mouse_decks.clicked_name is an array [ "top_left_deck" ] and deckChoice remains 0.

Is it possible I’m missing something simple here?
Would appreciate any help including how to troubleshoot something like this.
Thanks in advance

Hi @plonskipe, I suspect your .csv files are simply not uploaded to pavlovia, because they are not “hardwired” as a conditions file. To make sure that they get uploaded, go to experiment settings → online → additional resources and choose the files that the experiment needs manually.

1 Like

hi @ajus , I think they’re uploaded! The problem is that “deck_0.csv” is not a real deck. The code is intended to set “deckChoice” to a number 1,2,3 or 4 before loading a .csv file. Does that make sense?

Ah, sorry. I get it now. What I would do to debug the code is insert console.log(mouse_decks.clicked_name) before your if statements. This way, you could see in the console (ctrl + shift + k in Firefox) which value this variable actually assumes and figure out why the conditions are not working.

thanks, @ajus, this at least gave more information.
It looks like mouse_decks.clicked_name is set correctly, unless it needs to be converted from an array in order to match the if statements in the JS code at the end of routine.
deckChoice is printed to the console as well, so confirmed that it did not change from 0.
Any ideas?

Hm, as far as I can tell if(mouse_decks.clicked_name == "top_left_deck"){deckChoice = 1} should work fine. If it does not, I don’t really have another idea.

Thank you for helping to troubleshoot!
Hopefully someone else can pick up from here

Could you make the experiment available so I can have a look?


isn’t there semicolon missing before the last }?

If deckChoice is always 0, your if-statement does not work. But that is of no help. You figured that yourself. Did you ever printed “mouse_decks.clicked_name” to the console? What is its value?

Best wishes Jens

Should be available now. It’s a little unwieldy with more images in the directory than are used in the current task version. I can duplicate and remove the extra files later today if it’s a problem.

hi @JensBoelte , thanks for chiming in! I don’t see a missing semicolon but perhaps I’m not looking at the correct spot.
You’re right that the if statement is not working, and that’s the current issue. mouse_decks.clicked_name was printed in one of my previous replies; it is an array [ “top_left_deck” ] which to me appears correct. I’m no expert in JS though.


if(mouse_decks.clicked_name == "top_left_deck"){deckChoice = 1;}

I rely on PsychoPy‘s auto-translate feature to generate PsychoJS-code. Given that the experiment work offline but not online hints that the auto-translation did not work properly.

When mouse_decks.clicked_name returns an array, your if-construction will be false, IMHO based on what I read about arrays in JS. In JS you seem to use array.include(object) to check whether an element is part of an array.

Best wishes Jens

Hi @plonskipe, I tried the experiment using exactly the syntax I proposed above and it seems to work:


Did you maybe not try this specific syntax yet?

After that, there comes another error, but maybe that’s something for another tread.

Best, Adrian.

1 Like

thank you @ajus & @JensBoelte for helping with this!
I did try that syntax, but it was before I knew how to troubleshoot in the console, so I wrongly assumed that the error was related to the same issue.
There is in fact a different error.

Here is the image showing that the deckChoice variable is set correctly and the next error

@wakecarter @Becca not sure if y’all care about this, but it looks like the auto-translate feature in the builder had a small error when translating if statements from python to js in this instance

edit: the “undefined” error pasted here occurred because there was an unnamed column in position 0/1 in the .csv. There was another error with using “//” in JS file paths, but “/” worked.

Please could you show a screenshot of the auto code component you’re referring to?

Yes, it’s in the initial post just below the text “here is the end routine snippet that should set deckChoice to 1:4 based on click”

Try without the square brackets around the locations. If click_name returns a string it won’t equal a list.

Would you still be able to use a triple equals in that case (I think the === requires something like a variable type match in addition to content)
Just asking because I’m curious - ajus found one solution marked as such above