[Storyline] Javascript function library

Hello everybody,

I'm currently making a Storyline project to learn people how to use JavaScript to enhance their own Storyline projects and/or simplify it. Things are, I've managed to use the SetVar/GetVar methods but now I'm stuck with the use of a Function library.

I've followed the rather short explications found here: http://www.articulate.com/support/kb_article.php?product=st1&id=llwes8cn32vg  so I have that MyJSfunctions.js containing my functions I want to use:

function addition(a,b){

var res = a + b;

return res;}

(yes it's a very basic and rather useless function but it's for testing purpose)

and I have a script in a trigger that calls that function:

var num1 = parseFloat(prompt("Entrez le premier nombre"));

var num2 = parseFloat(prompt("Entrez le second nombre"));

var res = addition(num1,num2); 

alert("Résultat: "+res);

After publishing the project, I put the function-containing file in story_content as told and I'm encountering a problem with the script line that I have to put at "line 113" (I made sure the script line had the right file name in it of course) but the line 113 of my story.html is this:

So yeah, as expected pasting the line there didn't do much and the function was never called succesfully (nothing happens after entering the two numbers) so I think my problem is that it's not at the good location.

If my diagnosis is correct and as I'm no expert on html can someone tell me more accurately where do I have to put the <script LANGUAGE="JavaScript1.2" SRC="story_content/Whatever.js" TYPE="text/javascript"></script> line please? 

Thanks in advance

4 Replies
Carlos Rubinstein

Hi JR,

Great idea - 

I'm not sure that line 113 is critical. If you open your story.html in a ext or html editor, find the line that's just </head>. Above it, you'll see the syntax of how Storyline references the user.js and story.js libraries.

I suggest you duplicate one of those <script...> lines and edit the last one (closest to </head>) to reflect the name and path to your library. 

Good luck, and please post your results!

Cheers,

Carlos

JR G

Thanks for answering but I noticed a day ago that they changed the help section with the more explicit:

"place your custom JavaScript file in the story_content folder of your published output, and add the following line of code to the story.html file before the closing </head> tag."

and it was obviously here as they were the other javascript files loading lines.

But even with that fixed, I couldn't call functions that weren't explicitely written in the calling script. Whenever I tried I had the "I stop executing at this line" error, which means that I used an undefined expression at this given line, and it disappears if the function is declared in the script.

Am I supposed to make something like an #include or a "function name(arguments)" in the script like in C? If someone know please tell me.

World, I need your help :(