Cant execute JavaScripts
Nov 13, 2014
I'm doing a game and trying to add a dice whit JavaScript, all works fine but the JavaScript command dont executes when the dice is clicked.
I downloaded a project of the comunity forum where it have a dice and its suposed to work reading the coments but when i publish that project it dont executes the comands too. So, i dont know if im skiping something when publishing the project or something.
This is the code that im using:
var number = Math.floor(Math.random()*6);
GetPlayer.SetVar("dado",number);
Here is the file of my project.
19 Replies
Are you testing your project locally (on your harddrive)? If yes, ten the JavaScript is likely blocked by your browser's security settings. Try uploading the published content to some server and test again or publish for CD and test locally.
Hi Jorge,
This article includes a few free web servers you could utilize to upload the course.
I tried uploading the game to dropbox and testing it on Chrome, mozilla and Explorer 11. And the game launches fine but the "execute Javascript" trigger dont works, the command dont executes. I leave here the project and this is the published one
https://dl.dropboxusercontent.com/u/40237436/storyline/dragones%20y%20escaleras%20-%20Storyline%20output/story.html
Did you ever get your JS to execute? Here we are, four years later, but my execute JS function has just stopped working for no obvious reason. I've rebooted. I've updated SL360. Nothing seems to work. There is clearly some oddball situation that renders the JS execute function inoperable in SL.
Hi Russell,
What type of Javascript function are you executing? Did it work in a previous update of Storyline 360?
Some Javascript elements changed when we built Storyline 360, but if your function used to work in a previous update, there may be something else going on here.
I'm using window.history.back(); and it's been working fine in SL2 and SL360.
I've stumbled upon these cases of it not working when opening older SL2 projects with SL360. Most work with the JS, but I've found a couple that ignore any JS I put in. And for no apparent reason that I can see.
Good information, Russell. We're happy to have a closer look at a working and non-working file to compare.
Hi Russ, have you checked the developer console for any errors?
Hey there, Phil. Thanks for chiming in. No, I'm not familiar with that. Is this a facility within SL360?
It is a browser function to show any javascript errors, may help to see where the problem is.
https://webmasters.stackexchange.com/questions/8525/how-do-i-open-the-javascript-console-in-different-browsers
Should help you find it
Ok, I see. Not a part of SL. Since I'm only trying to execute one line of code, and a line that works in other projects, I doubt that the console could help very much.
Do you have other code in the project?
What is the line?
Sent from my iPhone
Ok, standby, I think we're on to something...
The console complained of a syntax error, in particular, a colon instead of a semicolon on one of lines. I have the JS on every slide so I went through and sure enough, one had a colon. I corrected that, and retested. The same problem and now it says I still have one more. I'm looking for it now. It is odd (or is it?) that one syntax error would make all the JS in the project inoperable. I suppose if it does the equivalent of a compile it might act that way. Anyway, I'll report back shortly.
It says the nasty colon is in line 18. There are 16 slides and the last slide has two JS calls in it. Is it possible user.js has gotten corrupted and has an extra, unreferenced line of code?
I'm considering just deleting the final/bad window.history.back(); from user.js and giving it a try, What you think?
It is probably in there somewhere perhaps even on the slide master.
One bad line can break all of it because of the way storyline incorporates it in one file.
Often it is the line above that is wrong.
Sent from my iPhone
Nothing changes over the years, Phil. You are still the most brilliant SL developer I know. Thanks so much.
And for everyone else, one bad line of JS and everything goes down the toilet.
Thanks Russ :-)
Sent from my iPhone
And as a postscript to this, I never was able to find the offending line of code in my project. So I corrected it in user.js and now everything works swimmingly.
This discussion is closed. You can start a new discussion or contact Articulate Support.