So your task was running perfectly offline, then you pushed it online, and it doesn’t work - why?
To run in the browser your python experiment is translated to Javascript (PsychoJS). Not everything you use in python can be autotranslated to JS (e.g. whole python libraries such as numpy).
The forum is always there!
Undefined errors:
feedbackText = ' target hit! %.2f seconds'%(mouse.time[0])
This means that although something was defined when you ran in python, that variable didn’t make it to the JS code..
Sometimes we might get an error that doesn’t refer to a variable, but it refers to a function or library we tried to use.
If we encounter a translation error. There are several places we should check for support:
e.g. If we search ‘round’ in the crib sheet, we can see that the JS version of this is provided:
round = function(num, n=0) {
return +(Math.round(num + ("e+" + n)) + ("e-" + n));
}
Add a code component in your first routine ‘initJS’. Then let’s try and run online again.
Let’s try and push the experiment we made yesterday online and talk through any errors we encounter.
We have already seen that the variable “t” can be used to refer to the current time in the trial. But what if we want seperate clocks that run independantly relative to something else, locally we would use:
myClock = core.Clock()
But online, that causes an error.
Exercise: What’s wrong? How to we fix it? (Hint: crib sheet)
Solution (note the code type here):
Sometimes you might not get an error message, but things “don’t work” - what do we do here?
you can open developer tools in your browser (see crib sheet) This will tell us where our (which line) error is occuring
We can then open up our JS file and take a look further.
There are several other tools that can be useful including:
Let’s practice debugging errors, then play with advanced plugins we can use online ( Advanced online).
Then we will try Coding a full experiment.