JS Syntax error!

Hello! I am attempting to transfer my experiment from PsychoPy (v2024.2.3) to Pavlovia.
When I attempt to select “Write experiment as a Java Script (JS) script” I get the following syntax errors:
Generating PsychoJS script…

1378.8456 EXP Imported /Users/danielaibarra/Desktop/Decoy/Baseline_PreTest.xlsx as conditions, 20 conditions, 13 params
1378.9047 ERROR invalid syntax (, line 1)
1378.9048 ERROR invalid syntax (, line 1)
1378.9533 ERROR invalid syntax (, line 1)
1378.9534 ERROR invalid syntax (, line 1)
1378.9652 ERROR invalid syntax (, line 1)
1378.9653 ERROR invalid syntax (, line 1)
1379.8954 EXP Imported /Users/danielaibarra/Desktop/Decoy/Baseline_PreTest.xlsx as conditions, 20 conditions, 13 params
1379.9606 ERROR invalid syntax (, line 1)
1379.9607 ERROR invalid syntax (, line 1)
1380.0167 ERROR invalid syntax (, line 1)
1380.0168 ERROR invalid syntax (, line 1)
1380.0322 ERROR invalid syntax (, line 1)
1380.0323 ERROR invalid syntax (, line 1)
1381.8315 INFO Investigating repo at /Users/danielaibarra/Desktop/Decoy

However, when I attempt to run the current script on Python it works perfectly. I assume the error is due to my custom code? I don’t see how to change this since PsychoPy automatically translates the custom Python code into JS code.

My custom code was:
if MelodicTone.status == FINISHED:
continueRoutine = False
elif BuzzTone.status == FINISHED:
continueRoutine = False
elif text_blankonesec.status == FINISHED:
continueRoutine = False

and PsychoPy translated it to:
if ((MelodicTone.status === PsychoJS.Status.FINISHED)) {
continueRoutine = false;
} else {
if ((BuzzTone.status === PsychoJS.Status.FINISHED)) {
continueRoutine = false;
} else {
if ((text_blankonesec.status === PsychoJS.Status.FINISHED)) {
continueRoutine = false;
}
}
}

If anyone has any indication as to why I am experiencing syntax errors and am unable to sync my experiment to Pavlovia please let me know!

There might be something earlier in your experiment, such as in the expInfo dialogue box.

how?

Hello

You need to provide more information. We just have the information you provide us with. You suspect that the error is in your custom code but that does not have to be the case.

You could, for instance, post a locally running toy-version of your experiment, that you can’t sync, in the forum.

Best wishes Jens

Hello, I am getting the same error:

ERROR invalid syntax (, line 1)

I wanted to create the same project that is working and syncing fine- but with a slight change, I added a mask in this new project after showing stimuli. So everything is the same. So it starts with screen scale blind spot and so on. At first i realized i accidentally left duration to credit card image to 1s so i changed it, cleared cache, saved exp again and synced again but I-was-seeing credit card image and it disappeared. Then now I added a consent code and loop before the screen scale so at first consent should be shown. But again although i cleared cache and tried with different browser, I am seeing credit card imag and it disappears. And that error I got. What might be the issue here? I am adding the first 10 lines of the code is that it?Thanks a lor for your guidance!

/************************

  • Newversionwmask *
    ************************/

import { core, data, sound, util, visual, hardware } from ‘./lib/psychojs-2024.2.4.js’;
const { PsychoJS } = core;
const { TrialHandler, MultiStairHandler } = data;
const { Scheduler } = util;
//some handy aliases as in the psychopy scripts;
const { abs, sin, cos, PI: pi, sqrt } = Math;

Hello

I do not speak PsychoJS, sorry. I rely on auto-translate from PsychoPy to PsychoJS. Do you have the Python-code?

Best wishes Jens

1 Like

Hi

Thanks for the quick response! I actually directly copy pasted this from the coder i thiught the error was referring to this but… after i wrote this entry as i read similar entries,I checked if i missed anything when copy pasting (transferring) experiments and turns out I missed adding some parts of the code and incorrectly referred to the stimuli i should be refereing to in mouse component, (clickable stimuli)now I double checked and added. But 1-consent routine wont work. Its supposed to end the experiment if n is pressed, even i press n i see the screen scale part and credit card image disappears again.

What could be the issue?

Thanks a lot for the guidance!
Best regards,

Hello

Your answer is rather confusing. The coder is used to write PsychoPy-experiment in Python, not PsychoJS-programs. Did you mean the builder? Did you use code-components which were auto-translated?

If you have a new problem, better start a new thread with a new heading. Given that you do not provide the routine and component you use for for ending the experiment nobody will be able to tell what does not work.

Best wishes Jens

hello

Yes in my experiment i used code components some of them were auto-js some of them were both some of them were js but these were fine before, i had no problem syncing from the original experiment project, plus screen scale and blind spot is not something i wrote so js- both should not be causing issue i think.

I tried to create a second project, for that I was going to just add masks after stimuli, so i directly copy pasted routines to a new folder. I got that error, then i thought i should be looking at the coder cause i didnt know what first line (ERROR invalid syntax (, line 1))means so what I sent is from the coder.js

As I said when I realized I missed adding some code from my working experiment to this one, I changed them, now I am able to see the consent but still the next routine which is scaling, credit card image disappears again, regardless of consent I think.

and I get the same error but no problem with syncing.

Here are some screenshots:





Code I am using for consent:

show_task = 1 #show everything

if ‘n’ in key_resp_3.keys: # Assuming ‘n’ is the key for ‘No’

show_task = 0

and loop starts from at the end of consent to the at the end of experiment.

Hope its more clear now!

Thanks a lot!

Best regards,

I meant this part:

Hello

The PsychoJS-part look ok.

Where and when do your use the consent routine? See the following example. this routine follows the consent routine. If ‘a’ is pressed the experiment ends.

Begin routine tab

if key_respGruss.keys != "a":
    continueRoutine = False

End routine tab

if key_respGruss.keys == "a":
    core.quit()

Best wishes Jens

1 Like

code_both Begin Experiment is missing semi colons on the JS side.

2 Likes

hello, thanks a lot! Where exactly I should be adding semicolons? I am not familiar with js.

Thank you very much!

At the end of every line to separate one command from the next (as per the auto translated code).

1 Like

am I missing something because I still get : ERROR invalid syntax (, line 1)

Just changed to autoJS and still the same


error: ERROR invalid syntax (, line 1)

Hello, thanks so much for the quick response! Consent was the first routine. I was using
if ‘y’ in key_resp_3.keys:
show_task = 1 #show everything
if ‘n’ in key_resp_3.keys: # Assuming ‘n’ is the key for ‘No’
show_task = 0 # Exit the experiment if they do not consent
In the end routine tab with loop starting at the end of consent through the end of the experiment.
But I think there is a problem with this not translating to js? I also tried your version.Am I missing anything?

Thanks so much!
Best regards,


Hello

This did not auto-translated.

if key_resp_3.keys == "n":
    core.quit()

should translate to

if ((key_resp_3.keys === "n")) {
    core.quit();
}

Try resetting the Code type by switching to Py and back to Auto-> JS. If this does not work, set the Code type to both and copy&paste the PsychoJS code to the PsychoJS side.

Best wishes Jens