Very simple JavaScript call not returning a variable
Mar 26, 2014
I'm can't get JavaScript to manipulate variables fetched from Storyline and I have no idea what I'm doing wrong. Probably something idiotically straightforward - I hope so!
My very simple test sends two text variables using JavaScript, concatenates them and should send back a single, combined variable.
This is the JavaScript:
var FirstName = player.GetVar("First");
var LastName = player.GetVar("Last");
var FullName = FirstName + Last Name
var player = GetPlayer();
player.SetVar("CompleteName",FullName);
I attach the Storyline file. I published it for CD and have tried it on different Windows 7 and XP systems but still no variable is being returned. What a pain it is to simply manipulate text in this way, inside or outside of Storyline. I used Authorware for 20 years and have been spoiled by terrific facilities in this area!
Any ideas?
Many thanks, Tim
3 Replies
This has concatenate code in that works
https://www.dropbox.com/s/nfmi3ibb8lddvpx/Concatenate%20Name.story
Brilliant! Thanks Phil for your really fast response and with a relevant working example.
It was a syntax error of mine - when I moved the line 'var player = GetPlayer();' to the TOP of the code it worked perfectly.
Great support, thank you.
Phil, at the risk of being greedy I've also been trying without success to get the JavaScript code to work to save a Storyline variable to a .txt file, in a CD-published program.
I used the exact code given in the Support page athttp://www.articulate.com/support/storyline/javascript-best-practices-and-examples but it's not writing a txt file. I've looked through the various threads on this but I'm still stuck.
My JavaScript code is below, I set the SL variable 'First' to a name:
var fso = new ActiveXObject("Scripting.FileSystemObject");
var s = fso.OpenTextFile("C:\\Test.txt", 8, true, 0);
var name = player.GetVar("First");
s.WriteLine("Name: " + name);
s.WriteLine("==========");
s.Close();
Many thanks, Tim
This discussion is closed. You can start a new discussion or contact Articulate Support.