Need Help with Javascript - concatenating and setting variable in Storyline

Hi,

I'm trying to concatenate several text fields into one, and I can't get the javascript to work. The variable I'm trying to set is "ConceptsBehaviors".

When I test, the field is blank.

What am I doing wrong? Also, I'm not sure if I need the quotes around the "/n" if I want a line return in the text field.

Thanks in advance...

var player = GetPlayer();
var Concept1 = player.GetVar("Concept1");
var Concept2 = player.GetVar("Concept2");
var Concept3 = player.GetVar("Concept3");
var Behavior1= player.GetVar("Behavior1");
var Behavior2= player.GetVar("Behavior2");
var Behavior3= player.GetVar("Behavior3");
var ConceptsBehaviors = "Concept 1: " + Concept1 + " - " + "Behavior 1: " + Behavior1 + "/n" + "Concept 2: " + Concept2 + " - " + "Behavior 2: " + Behavior2 + "/n" + "Concept 3: " + Concept3 + " - " + Behavior 3: " + Behavior 3);
player.SetVar("ConceptsBehaviors", ConceptsBehaviors);
3 Replies
Matthew Bibby

This looks problematic:

var ConceptsBehaviors = "Concept 1: " + Concept1 + " - " + "Behavior 1: " + Behavior1 + "/n" + "Concept 2: " + Concept2 + " - " + "Behavior 2: " + Behavior2 + "/n" + "Concept 3: " + Concept3 + " - " + Behavior 3: " + Behavior 3);

Try this instead:

var ConceptsBehaviors = "Concept 1: " + Concept1 + " - " + "Behavior 1: " + Behavior1 + "\n" + "Concept 2: " + Concept2 + " - " + "Behavior 2: " + Behavior2 + "\n" + "Concept 3: " + Concept3 + " - " + "Behavior 3: " + Behavior3;

I've bolded the parts that I've changed. Hopefully, you'll be good to go now.

Amber Starfire

Thank you, Matthew! I had already figured out that I needed to use the backslash instead of the forward slash to create the new line, and saw the extra parenthesis, but no matter how often I went over it, the space in the last variable name eluded me. That did the trick!

I don't use javascript very often, and every time I do I have to relearn it. <sigh>