Hi everyone,
I’ve been developing an experiment for a while, and suddenly I encountered a strange issue. When I sync my project with Pavlovia, it starts deleting the creation of core PsychoJS
variables from the JS code.
Even if I manually add them back, the next sync removes them again.
Here’s a screenshot comparing the commits to show what’s happening:
Has anyone encountered this before? Any idea why this might be happening or how to prevent it?
Thanks in advance for your help!n.
What error do you get if you don’t edit the JS code?
The answer is (almost) never to edit the generated code
When you create an experiment in Builder, PsychoPy then generates a Python file which you can use to run the experiment locally and two JavaScript files suitable for running the experiment online (using current and older browsers).
If something doesn’t work, there may be a temptation to make edits directly to the Python/JavaScript files rather than the Builder file. However, this is generally a bad idea for two reasons:
The process is o…
What version of PsychoPy are you using?
Thanks.
Is your “use version” in Experiment Settings blank? Do you have any loops? Do you have any code referring to currentLoop?
The use version is not blank, but contains 2024.2.0, I got multiple loops in the experiments but no code referring to currentLoop
Did you check an incognito tab?
Okay. Please could you add me (Wake) as a developer and I’ll take a look.
However, first please set it to inactive and then piloting/running again.
Hi.
I’ve taken a look and I’m pretty sure that the issue is that you are writing JavaScript code that isn’t compatible with PsychoJS. You have disabled your text components and replaced them with JS only code components. You implied that previous versions of the experiment worked fine. On what date did this experiment last run and what did you add next?
Begin Routine
let introDiv = document.getElementById("introTextDiv");
introDiv.innerHTML = introText;
introDiv.style.display = "block";
End Routine
// Hide intro text at end of trial
let introDiv = document.getElementById("introTextDiv");
if (introDiv) {
introDiv.style.display = "none";
}
Here are some threads with the same issue:
URL of experiment: AudFlankTest_legacy [PsychoPy]
Description of the problem:
Hello all! I seem to keep receiving ReferenceErrors when attempting to run this experiment online. The variables never seem to be declared in the auto-generated JS file, which I seem to recall has been the case previously. For example, in the below snippet, currentLoop is never defined anywhere using var/let/etc.
async function updateInfo() {
currentLoop = psychoJS.experiment; // right now there are no loops
..…
URL of experiment: https://run.pavlovia.org/learningdevlab/3b_complex_binctl/html
Description of the problem: When I click to pilot my experiment, I get through the dialog box, but then immediately get a frameDur error
when I check the javascript console, my error is related to code that was generated automatically by psychopy/pavlovia
[Screen Shot 2020-03-11 at 12.21.56 PM]
// store frame rate of monitor if we can measure it successfully
expInfo['frameRate'] = psychoJS.window.getActualFr…
and relevant tips
Builder isn’t Coder
I strongly discourage the use of PsychoPy Coder for the creation of psychology experiments because Builder is easier to debug, share with others and translate into PsychoJS for use online.
If you already have an experiment written in Coder, pasting the code into Builder code components is not sufficient to turn it into a Builder experiment. The logic of how to arrange an experiment is slightly different because of the way Builder works with components, routines and loops.
F…
Use Auto → JS code components wherever possible
Even if you aren’t planning to run your experiment online, using an Auto code component will help you spot syntax errors in your Python code.
[image]
There are some cases where valid Python code comes up as a Syntax error on the JavaScript side but these are rare and, when you encounter then, you can switch to a Both code component and edit or delete the JavaScript side to highlight the fact that they contain code that won’t run online unedited. …
Own up to AI
When trying to help people on the forum or through consultancy we are experiencing an increase in the amount of idiosyncratic or opaque code, coming from novice programmers who. ChatGPT and other AI tools can be a great help with programming tasks but they are not experienced with the architecture of PsychoPy Builder. If you use them, please add a comment to your code along the lines of # Created using ChatGPT to create random pseudo-words. Adding your main prompts as comments might…
Thanks! found the problem:
This row isn’t compatible with PsychoJS:
slider_value = document.querySelector('input[name="expectation"]:checked')?.value;
Instead, I changed it to:
let selectedInput = document.querySelector('input[name="expectation"]:checked');
let slider_value = selectedInput ? selectedInput.value : null;