Uncaught SyntaxError: Unexpected identifier

URL of experiment: https://gitlab.pavlovia.org/akarnick/br-update-group-0

Description of the problem:

Hi there, so sorry, but I’m super new trying to get an experiment to run online that is running fine locally. I have uploaded my experiment to gitlab and have figured out how to set it to piloting to see how it works, but when I try to run it, it just becomes stuck on “initialising the experiment”. I checked the quickstart guide and crib sheet and developer tools in Chrome threw up the following errors:

  • Tone.js v13.8.6 *

/akarnick/br-update-group-0/html/BR_Update_Group0.js:2769 Uncaught SyntaxError: Unexpected identifier

/favicon.ico:1 Failed to load resource: the server responded with a status of 404 ()

I’m not sure about the failure to load resource error, but I checked line 2769 in the JS code, and this is the code (line 2769 starts with “if ((((sex.getRating() is not None)” etc.):

// *demo_cont_text* updates
    if ((((sex.getRating() is not None) and (race.getRating() is not None))) && demo_cont_text.status === PsychoJS.Status.NOT_STARTED) {
      // keep track of start time/frame for later
      demo_cont_text.tStart = t;  // (not accounting for frame time here)
      demo_cont_text.frameNStart = frameN;  // exact frame index
      
      demo_cont_text.setAutoDraw(true);
    }

Does this mean that the experiment won’t initialize because of an error in the code here?

Hi atkar!

Yes, there is an error at that line. In JS, you should write ‘undefined’ instead on ‘None’. In the cribsheet, see the section: Translations that require manual editing

Cheers Thomas

1 Like

Thank you so much @thomas_pronk! That is extremely helpful.

I know this is probably a dumb question, but before I make a huge mess on my system should I edit the dlgs.py file on my computer to somehow set “None” to be re-interpreted as “undefined” when translating to JS in Builder? I am referencing the link below from the crib sheet?

If not, how should I proceed? I use the terminology “[something] is not None” quite a bit for the start condition in my experiment to initialize events based on someone’s responses. Would placing a code component at the beginning of each routine with the following code and then manually editing the JS code to say “undefined” rather than “None” fix the problem? And if so, what should I put in builder for the start condition?

        if slider_rating.status == NOT_STARTED and slider.getRating() is not None:
            # keep track of start time/frame for later
            slider_rating.frameNStart = frameN  # exact frame index
            slider_rating.tStart = t  # local t and not account for scr refresh
            slider_rating.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(slider_rating, 'tStartRefresh')  # time at next scr refresh
            slider_rating.setAutoDraw(True)
        if slider_rating.status == STARTED:  # only update if drawing
            slider_rating.setText(int(slider.getRating()), log=False)

Again, I’m very sorry for all of the questions. I’m just trying to get started and am so grateful for all of your help!!

My hunch is that editing dlgs.py won’t help you out here, however…

Yes, I think that’s the way to go for fixing this particular problem. Not sure what you mean with this part

Thank you @thomas_pronk! This helped a lot!

For reference, I was trying to have certain components appear based on starting another component. In builder I had entered things like the following into the “Start (condition)” field for the component that I wanted to start when someone entered their race and sex.

race.getRating() is not None and sex.getRating() is not None

To fix the code in JS I created a code component and under “every frame” I created a variable that included the code above. I then edited the code in the JS window (after switching the psycho>JS translate mode to “both”) and replaced “null” wherever it appeared with “undefined”. I then placed the name of the variable I created preceded by “$” in the “Start (condition)” field for the component that I wanted to start conditionally and the errors went away!

I got some more errors after that, but I believe I now know how to problem solve them thanks to your help!

Hi all, I’m having another issue debugging and I was wondering if anyone else has had the same issue I am having. In my experiment I need to have participants rate a series of items, then rate them a second time, then finally rate them a third time. I need them to do this twice and I have a list of 80 items they might view. I want the order of the items to be randomized once at the beginning, but then to be displayed in the same order for each block. The way I did this originally was with the following python code snippet:

randblock = np.random.choice(80,replace = False, size = (2,40))
randblock1 = randblock[0]
randblock2 = randblock[1]

This generated two random blocks of forty integers from 0-80 without repeating any integers twice. Then for the trial loops I entered $randblock1 or $randblock2 into the “selected rows” field depending on which block I wanted to display.

Obviously, this fails when converting into javascript since javascript can’t interpret numpy code. Is there a way of doing this that is compatible with javascript? I’ve looked around online and have not been able to find an answer.

1 Like

Hi again Atkar,

This seems to point in the right direction:

I found it as follows:
https://duckduckgo.com/?t=ffab&q=javascript+random+sequence+no+repetitions&ia=web

Cheers, Thomas

Thank you so much @thomas_pronk ! I’m currently working on and testing a workaround and will post the results when I am finished. This is extremely helpful.

Go for it! A word of warning though, algorithms like these can get a bit slow when randomising large numbers of trials and/or applying stringent repetition restrictions.