../_images/OST600.png

Debugging online§

1

Debugging online§

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).

2

Debugging online§

3

General tips for getting online§

  1. Always check the status of online options status of online options before making your experiment
  2. Push your experiment little and often (don’t make your full experiment perfectly locally and then try to push it online)
  3. Read the crib sheet
  4. Check out the psychoJS documentation

The forum is always there!

4

Common errors§

Undefined errors:

feedbackText = ' target hit! %.2f seconds'%(mouse.time[0])
5

Common errors§

../_images/notDefinedErr.png

This means that although something was defined when you ran in python, that variable didn’t make it to the JS code..

6

Common errors§

../_images/functionErrorRound.png

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.

7

Resources§

If we encounter a translation error. There are several places we should check for support:

8

Resources§

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));
}
9

Adding JS code§

Add a code component in your first routine ‘initJS’. Then let’s try and run online again.

../_images/defineRoundJS.png
10

Adding JS code§

There are several handy functions you might want to include at the start of your experiment in a .JS component which might make things easier in the long run:
  • append - for adding to lists
  • thisExp - for adding data to the experiment handler
  • shuffle - for shuffling and randomly selecting items from lists
11

Group Exercise§

Let’s try and push the experiment we made yesterday online and talk through any errors we encounter.

Add ons we might also want to discuss:
  • counterbalancing online
  • bot checkers and online checks (e.g. has our participant walked away? is our participant pressing the same key repeatedly?)
12

Other errors§

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()
13

Other errors§

But online, that causes an error.

../_images/constructorErr.png

Exercise: What’s wrong? How to we fix it? (Hint: crib sheet)

14

Other errors§

Solution (note the code type here):

../_images/clockConstructorFix.png
15

Fnding errors: Developer tools§

Sometimes you might not get an error message, but things “don’t work” - what do we do here?

../_images/initialisingScreen.png
16

Fnding errors: Developer tools§

you can open developer tools in your browser (see crib sheet) This will tell us where our (which line) error is occuring

../_images/developerTools.png
17

Fnding errors: Developer tools§

We can then open up our JS file and take a look further.

../_images/syntaxErrorJS.png
18

Other useful tools§

There are several other tools that can be useful including:

19

Next up!§

Let’s practice debugging errors, then play with advanced plugins we can use online ( Advanced online).

Then we will try Coding a full experiment.

20