Javascript not being called

Jan 25, 2023

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

5 Replies
Jim Owen

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

Math Notermans

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.