Forum Discussion
Javascript not being called
Hi, I am not conversant in JS, but have copy-pasted a script to be executed when timeline starts on a slide. However, it looks as if it is not being called at all.
The Trigger is "When timeline starts on this slide, Execute Javascript", and here is the JS I am trying to execute:
var player=GetPlayer();
player.SetVar("varRandom", Math.floor((Math.random()*1000)+1););
alert("It is " + player.GetVar("varRandom"););
I publish the course, and run it and nothing happens. I also have a TextBox on this slide which displays varRandom. It is always still the default, of 0.
What am I missing?
(btw I am aware that there are easier ways to get random numbers. This is just dummy code to debug this problem. IRL the code will be different.)
- Jürgen_Schoene_Community Member
there are two small errors in the script
with a really strange error message in the console (-> F12)
here the correct version
var player=GetPlayer();
player.SetVar("varRandom", Math.floor((Math.random()*1000)+1));
alert("It is " + player.GetVar("varRandom"));Jürgen
- JimOwen-707d222Community Member
Thanks, that fixed the sample code, one step closer...
Now, the actual code is not running, so something is wrong there too. Here is the actual code I'm trying to run. It uses Twilio to send me a text message every time someone opens my project. Any idea what's happening here?
I got this code from here:
https://www.twilio.com/blog/2016/04/send-text-in-javascript-node-in-30-seconds.html
var twilio = require('twilio');
var player=GetPlayer();
player.SetVar("varRandom", Math.floor((Math.random()*1000)+1));
//alert("It is" + player.GetVar("varRandom"));
var client = new twilio('redacted', 'redacted');
client.messages.create({
to: '+12065016936',
from: '+14065016936',
body: player.GetVar("varRandom") + ' Splash screen'
});
- Jürgen_Schoene_Community Member
this is javascript for node.js on a web server enviroment
this is not working in a browser
- JimOwen-707d222Community Member
So I cannot do this at all you're saying?
- MathNotermans-9Community Member
You need to use Twilio for the browser.
https://www.twilio.com/docs/voice/sdks/javascript
So add twilio.js or twilio.min.js to your Storyline project for example by using a WebObject.
As shown here... ( https://community.articulate.com/discussions/articulate-storyline/how-to-add-jquery-or-anyother-external-javascript-library-to-storyline )
Then you should be able to enable and use Twilio.