Using JavaScript to write StoryLine 2 variables to a .txt file

Since my company has no LMS, I'm testing some JS in SL2.
the only pieces of code that seem to work are these:

var player = GetPlayer();
player.SetVar("MyVariable", "SampleValue");

What I try to accomplish is this:

function ThatSkillz() 
var fso = new ActiveXObject("Scripting.FileSystemObject");
var s = fso.OpenTextFile("C:\\Test.txt", 8, true, 0);
var player = GetPlayer();
var name = player.GetVar("NameEntry");
var score = player.GetVar("SCORE");
s.WriteLn(name + "\t" + score);

This code is triggered with a button click. But once published, the button just animates but the code fails (or isn't even executed perhaps?)
Can anyone explain me the correct way to deal with this? <<<

Basically I want to write the values of "NameEntry" & "SCORE" to a .txt file.
function ThatSkillz() does not work from within the SL2 script entry field.
I guess it could work if I edit the SL2 output files and insert the code there?
I'd like to hear from other people's experiences with the use of JS in SL2.<<<


3 Replies
Ashley Terwilliger-Pollard

Hi Stefan,

Thanks for reaching out here - and althought lots of users in the forums implement Javascript elements, it's not something that we can assist with in terms of support. You may want to begin by reviewing the best practices here while you wait for community members to chime in. Additionally a common error is testing the published output locally vs. uploading it to the intended web site or server. You'll want to confirm you're testing in the intended publish environment. 

jacques roux

Hi Stefan,

I think the only way you will be able to write to your local file is through Internet Explorer, and then only when you have enabled ActiveX and changed some settings.

Do you need to to have the values written to a text file, or will a simple JS Alert perhaps do?

This works, but I suspect you know that :)

var player = GetPlayer();

function ThatSkillz() {

var name = player.GetVar("NameEntry");
var score = player.GetVar("SCORE");
alert(name + "\t" + score) };


Viewing your HTML file locally from your file system will give you the Storyline JavaScript warning. I always use Firefox to view local Storyline files - when you get the FireBug plugin it will allow you to execute all your Storyline JavaScript from your hard disk.

Stefan Heyninck

I needed the code to write to a file that is closed and ready to receive further inputs.
So no a JS Alert doesn't cut it.

I needed a workaround for the fact that we don't have an LMS. I wanted some variables to be set in the background depending on the user's behaviour so I could track how my content was being used. I had all the variables and triggers set up and then I realised there was no way for me to keep track of them.

Meanwhile I got it working under strict conditions but I've abandoned the whole idea since I can't force the required ActiveX settings on my users anyways...

I'll keep the JS Alert in mind for other purposes though. Thanks!