I'm building a simulation in storyline, the only bit i'm stuck on is how to save data.
I'm setting variables with data inputs no problem, but then (i guess using trigger javascript) need to write and read from storyline to either excel or some other kind of data file. I'm not a coder and am struggling to get it working using any Javascript resources I can find.
Anyone had any luck getting storyline to write to and read from either text file / excel file / database or cookie etc using triggers and javascript? or if not any support in how would be be good.
I know you posted this a while ago but if you still need help, I was able to write to a txt file using JavaScript. I have a button with a trigger that executes the JavaScript when pressed. This is the code with //comments to explain:
var fso = new ActiveXObject("Scripting.FileSystemObject"); //basically tells it you're using ActiveX
var s = fso.OpenTextFile("S:\\QC\\profiles\\krissymiller\\Test.txt", 8, true); //this opens the file, first is the path name (don't forget there are 2 \ and not just one, 8 means append to the file (1 is for just reading, 2 is for just writing), true means if there is no file by that name to create it, can do false to not create it
var player = GetPlayer(); //gets the player from storyline, everything comes from the player
var name = player.GetVar("username"); //gets the variable I called username
var score = player.GetVar("ScorePercent");
s.WriteLine("Name: " + name); //writes Name: name to the file on one line
s.WriteLine("Score: " + score + "%"); //writes Score: score% to the file on one line
s.WriteLine("=========="); //writes ===== just to separate the data
Thanks for sharing that here, as I know other users are always looking for Javascript code or examples to use. In case you haven't seen it yet, I also wanted to share the Javascript best practices we've outlined here.
Hi Krissy, I created two variables "name" and "email" I connected to a field, then I hooked a trigger javascript to keys. I tried to use your javascript code and I'm trying to understand why it does not work:
var fso = new ActiveXObject ("Scripting.FileSystemObject"); var s = fso.OpenTextFile ("C:\\stetod.txt", 8, true); var player = GetPlayer (); var name = player.GetVar ("name"); var email = player.GetVar ("email"); s.WriteLine ("Email:" + e-mail); s.WriteLine ("Name:" + name); s.WriteLine ("=========="); s.Close ();
After publishing I uploaded it to my server. The browser is no message warning, I would not want the browser did not write the file!
It seems all right but not function and do not understand why!
3 Replies
I know you posted this a while ago but if you still need help, I was able to write to a txt file using JavaScript. I have a button with a trigger that executes the JavaScript when pressed. This is the code with //comments to explain:
var fso = new ActiveXObject("Scripting.FileSystemObject"); //basically tells it you're using ActiveX
var s = fso.OpenTextFile("S:\\QC\\profiles\\krissymiller\\Test.txt", 8, true); //this opens the file, first is the path name (don't forget there are 2 \ and not just one, 8 means append to the file (1 is for just reading, 2 is for just writing), true means if there is no file by that name to create it, can do false to not create it
var player = GetPlayer(); //gets the player from storyline, everything comes from the player
var name = player.GetVar("username"); //gets the variable I called username
var score = player.GetVar("ScorePercent");
s.WriteLine("Name: " + name); //writes Name: name to the file on one line
s.WriteLine("Score: " + score + "%"); //writes Score: score% to the file on one line
s.WriteLine("=========="); //writes ===== just to separate the data
s.Close(); //closes the file
Hi Krissy and welcome to Heroes!
Thanks for sharing that here, as I know other users are always looking for Javascript code or examples to use. In case you haven't seen it yet, I also wanted to share the Javascript best practices we've outlined here.
Hi Krissy,
I created two variables "name" and "email" I connected to a field, then I hooked a trigger javascript to keys.
I tried to use your javascript code and I'm trying to understand why it does not work:
var fso = new ActiveXObject ("Scripting.FileSystemObject");
var s = fso.OpenTextFile ("C:\\stetod.txt", 8, true);
var player = GetPlayer ();
var name = player.GetVar ("name");
var email = player.GetVar ("email");
s.WriteLine ("Email:" + e-mail);
s.WriteLine ("Name:" + name);
s.WriteLine ("==========");
s.Close ();
After publishing I uploaded it to my server.
The browser is no message warning, I would not want the browser did not write the file!
It seems all right but not function and do not understand why!
Do you have any idea !?
Thanks