VS Code Javascript running in Storyline 360

Dec 07, 2021

If a javascript block runs without error in VScode, should I also expect it to run in SL360 ?

-- adjusting of course to replace variables in the script with calls to the player ie

player=GetPlayer();

var mytext= player.GetVar('SL360 var");

player.SetVar("SL360 var", myscore) --

Or does SL implement a subset or earlier version of javascript than VS code?

I obviously have a script that is misbehaving, with the console indicating 

Uncaught SyntaxError: Illegal continue statement: no surrounding iteration statement

after I publish and try to run the SL course slide.

 

2 Replies
Math Notermans

Some basic errors in your script. Can't say if that will run in VB but in Storyline it won't. Showing in the video how to use the console how to debug it properly and fix the errors.

So this is your code...

player=GetPlayer();
var mytext= player.GetVar('SL360 var");
player.SetVar("SL360var", myscore)

First thing that catched my eye was the missing var before player in the first line. But that wasn't a problem as you can see in the attached video.

In the video you see how i use the 'application' tab in the console to show 'user.js' the Javascript file Storyline produced so you can figure out what particular line of code is giving the error.

Then you notice that you use different 'brackets' for the SL360 var... in front a single one...after it a double one. Offcourse that causes the error. Fixing it like this...

player=GetPlayer();
var mytext= player.GetVar("SL360 var");
player.SetVar("SL360 var", myscore)

Again you notice it is not enough. Still more errors to fix. If you check your variables properly you will notice Storyline doesnot allow spaces in variable names. Yours has. So changing "SL360 var" to "SL360var" is the next step.

Publishing and testing again now show you didnot declare "myscore" in your code.
Fixing that...

player=GetPlayer();
var myscore = 22;
var mytext= player.GetVar("SL360var");
player.SetVar("SL360var", myscore)

And now your code works.
Personally i would change 2 more things...
Adding var before player... and a semicolon at the end.

var player=GetPlayer();
var myscore = 22;
var mytext= player.GetVar("SL360var");
player.SetVar("SL360var", myscore);

And you can work with "let" and "constants" that is more modern Javascript.

const player=GetPlayer();
let myscore = 22;
let mytext= player.GetVar("SL360var");
player.SetVar("SL360var", myscore);

Kind regards,
Math