Wan t to use a little JAVA Script in Articulate to separate the first letter of a given string (and send only this single letter back again ...)

Hello everybody

 

I wan t to create a "password game"

So i ask in Textfield for 4 Words

e.g

  • Hallo
  • Ich
  • Bin
  • Axel

I save all the 4 strings in a variable 

set var A = "Hallo"
set var B = "Ich"
set var C ="Bin"
set var D ="Axel"

now i want the JavaScript (or even if this somehow working direct in Articulate ...) to send back only the first letter of the input

so at the end the result should be

set var A ="H"

set var B="I"

set var C="B" and

set var D="A"

 

how can i do?

cheers

 

Axel

 

 

 

4 Replies
Matthew Bibby

Hi Axel,

Give this a try:

//Establish communication with Storyline:
var player = GetPlayer();

//Grab text from Storyline variables. This assumes your variables in Storyline are called varA varB varC varD. If they aren't, please update the bolded parts below to match your variable names.
var A = player.GetVar("varA");
var B = player.GetVar("varB");
var C = player.GetVar("varC");
var D = player.GetVar("varD");

//This will grab just the first letter of each string:
A = A.slice(0,1);
B = B.slice(0,1);
C = C.slice(0,1);
D = D.slice(0,1);

//Then this will pass the letters back to Storyline. Please update the bolded parts below to match your variable names:
player.SetVar("varA",A);
player.SetVar("varB",B);
player.SetVar("varC",C);
player.SetVar("varD",D);

Any questions or issues, let me know.