Concatenate a new value to an existing text variable

I've only started playing with this but wanted to open a discussion in case someone's already figured out how to do this.

I want to change the value of a text variable by adding a letter to the end of an existing text variable.  For example, when a user completes task one the variable will be assigned a value of "D".  When the user finishes task two an "o" will be added to the existing variable so that it will now be "Do".  After task three an "n" will be added to the existing variable so that the value is now "Don".  What I want to do is trigger an action when the value of the variable is "Done" (or whatever). 

Can text variables be adjusted this way?

8 Replies
Dave Cox

It would be easier to just about the value of the text variable to the string that you want. When the user completes the first task change the text variable to "D", and when the user completes the second task change the variable to "Do", and so forth. 

Editing text variable in the format that you describe is not something that is available directly in Storyline, however, you could do this with Javascript. In Javascript, it is a simple matter to add something to the end of your string variable.

var myTextVar = "D";
myTextVar = myTextVar + "o";

The value of myTextVar would now = "Do"

Steve Shoemaker

Thank for your response Dave.  Your suggestion would work if the learner did things in order but I want to use the variable value to see the order in which he/she did the steps.  If I just set the variable to "Do" when the user completes step 2 then I wouldn't know if he/she completed step 1 first.  I'm sure there's another way to insure that users complete the steps in a prescribed order but thinking about it made me wonder about concatenating text variables.

I'm also fairly new to Storyline and kind of test driving its capabilities.  I know Javascript pretty well and your code would work fine but I haven't gotten to the point of knowing how to incorporate Javascript into Storyline.  I'm going to look into that as soon as I post this!

Dave Cox

You may have to think out of the box a bit to do what you want.

Try this ... Create a numerical variable for each step, and create a variable to track how many steps the user has completed. As the user completes a step, update your step variable with the current user action number. This way you will create a list of variables that show the order of steps that user has completed their actions. You can then use this information however you need.

Steve Shoemaker

That will work because I can create variables that, when added together, will tell me the order of steps completed by the user.  That said, I think I'm going to experiment with Javascript.  I've seen where executing Javascript is an option in the trigger wizard (thanks Walt) and I see where to write the Javascript.  My only questions are knowing how to refer to elements (id/class) that I want to change and whether I need <script></script> tags.  The id/class question has nothing to do with this particular question about text variables but if, for example, I want to change the color of text with Javascript I need to know how to refer to the element I want to change.

Dave Cox

I'm not aware of any method to change the text color of the storyline content with javascript. If I remember correctly and even if you publish your project to HTML5, most of the items will not have id numbers for you to work with. You could however, use javascript to change the value of a custom variable, and the change the text state, (which could be a different color). You can trigger the state to change with the variable updates using a trigger.