Problems with running experiment online

Oh, you have a win.flip() call in your every frame code. You should get rid of that altogether if you can, both for Python and JS. It shouldn’t be needed (it should flip automatically on every frame) and it causes timing issues as I recall.

If you absolutely must have it, replace “win” with “psychoJS.window” in the javascript side of the code component, but again, generally you want to avoid calling win.flip() in a code component altogether.

Unfortunately, I apparently really need win.flip(), because if I remove it, the window does not flip anymore… Also, when replacing “win” with “psychoJS.window”, I get the following error:

TypeError: psychoJS.window.flip is not a function

OK, so I changed it to “psychoJS.window.callOnFlip()”, but now, the screen just freezes after the instructions :frowning:

Oh, I see what’s happening now. It’s the while loop. I didn’t even notice the whole thing was in a while loop, but that’s actually the root problem. Get rid of that and the window flipping stuff and it should all work.

“while continueRoutine” in an “Every frame” code component is basically redundant. PsychoPy will keep automatically showing frames until the routine ends, without any further instruction. Without the while loop, you won’t need to manually flip the screen, it will just flip automatically. Basically you put a whole separate routine control system inside the existing routine control system, which you can kind of do in Python (though I do not recommend it) but you really can’t do in JS. You can trust PsychoPy to take care of the basics for you and just tell it what to do on each frame, and it will figure out how to get to the next frame on its own.

Separately, the reason “callOnFlip” doesn’t work is that it doesn’t actually flip the screen, it just does something when the flip happens. It’s freezing because that function needs arguments and you’re not getting any. The code to make the screen flip in JS is not something I would want to put in a code component, I am virtually certain it would break the whole trial.

Thank you so much! Once again, I changed it, but now I keep getting errors of variables not being defined:

ReferenceError: frameDur is not defined

I know that in JS, variables need to be declared (like var frameDur; right?) first, but for some reason, that does not automatically happen. In fact, none of the variables are declared. Anything I can do about this? Sorry to keep asking questions by the way, your help is much appreciated!!

Ah, that message is actually a kind of red herring. See here: frameDur is not defined error

Basically you might be best off saving a copy of the experiment, and then re-uploading a fresh repository to Pavlovia, which should re-generate the JS code and hopefully fix this issue. If that doesn’t work, what we’ll probably need to do is a little manual editing of the JS file itself, which is a bridge we can cross if we need to but not before.

Re-oploading unfortunately did not fix the issue… The new repository is called:

CPouw/thesis_experiment_new

Unfortunately, I cannot upload the JS file on here directly.

I can see it. Yeah, it’s just completely failing to put in any of the variable declarations at all. This is a bug with PsychoPy’s code translation, if there’s something in the code it can’t handle it just fails spectacularly.

We’re going to have to narrow down which part of the code in particular is causing this failure. Let’s start by getting rid of core.quit(), which may or may not be the source of the issue but almost certainly won’t work. Then what you may need to do is try removing code elements one at a time, re-syncing after each one, and checking whether the js file has a bunch of “var” declarations near the top, until we figure out which one is causing it to trip.

Thank you so much, I figured it out! I had to remove “break” from the Each Frame tab, that caused the error. The vars are back now :slight_smile:

But of course, there is another error:

ReferenceError: IndexError is not defined

Huh, today I learned JavaScript doesn’t call that an IndexError. It’s not clear what error code it has for that, weirdly enough. Maybe just delete the nested “if” inside the catch statement, that way if it catches any error it will do that behavior.

Hm, I think I really need that if-statement, otherwise the experiment crashes after each sentence (so indeed, when an IndexError occurs)… At least, that is what it does in Builder.

The catch statement alone should prevent it from crashing outright, but remember that running locally uses Python while running online uses JS, so the behavior you observe on your own computer may not be the same as what you see running in Pavlovia when you have complex code elements like this one.

Okay, so it should look like this?

if ((kb.length > 0)) {
    if (_pj.in_es6("space", kb[0])) {
        try {
            nextWord = word_list.pop();
            text.setText(nextWord);
        } catch(e) {
            throw e;
            }
        }
    }
    rtList.append(kb[0][1]);
}

Throw is the crash, effectively. It’s the behavior that causes the experiment to end and it to throw an error. What behavior are you looking for when it’s out of range?

By default this should be safe:

if ((kb.length > 0)) {
    if (_pj.in_es6("space", kb[0])) {
        try {
            nextWord = word_list.pop();
            text.setText(nextWord);
        } catch(e) {
               console.log('word_list depleted');
            }
        }
    }
    rtList.append(kb[0][1]);
}

but you could also stick in "continueRoutine = false; " if you want the trial to end at that point.

Hm, what happens now is that the sentences don’t show up at all, but immediately after the fixation cross, it moves on to the pause & question. This is the case for the practice trials, but then when I get to the real trials, I get the following error:

TypeError: trials.addData is not a function

It looks like you may have fixed this on your own, but for whatever reason I guess it didn’t populate the name of your trials loops correctly. Does it work now?

Yes it works now! There were two variables called “trials” which interfered with each other. I changed one of them to “study_trials” and that fixed the problem. I am now stuck with one last problem: the font size. It keeps appearing too big in the browser, even if I change the size/height in the code. Do you have any idea how I can fix this?

What units are you using? For whatever reason I have seen this happen with “height” units, and then changing to “norm” units (which are very similar) seems to fix it.

Oh I had it on “from exp settings”, changing it to “height” fixed the problem! :slight_smile:

I have one more question about the data. I have completed one pilot experiment, but the data does not show up here when I click “download results”. Do you know why that might be?