Linking text entry field variable to other objects and functions

Hi everyone! 

I was wondering if there is a way to set up the text entry interaction so that it triggers a state change or animation on another object on the slide. For example: a progress bar loads to 50% when you type 10+ words into the filed; or: an object changes its state when you type in a certain key word. 

I'd be happy to hear your experience with this and would also be grateful if you could point me out to useful resources or previous discussions on the topic, since I couldn't find anything related. 

7 Replies
Ben McKinstry

Hi Alexandra,

This is a good idea, I do not believe it could be done with built in triggers but you could run some JavaScript to count the characters and change another variable if it is above 10 characters.

Rough idea would be

var player = GetPlayer();
var txtString = player.GetVar("txtVar");

player.SetVar("countChar", txtString.length);

 

The code above will check the variable txtVar and count the characters in it then set a variable countChar to that number, you could then use triggers with conditions to check if it is above a number and change the progress bar based on that.

Walt Hamilton

The real problem you are going to face is that it appears you want to trigger an action while the learner is typing. SL ignores what you are typing until the field loses focus, which happens when there is a Tab, Return, or click. At that time the variable attached to the field is updated, and you can use the change of the variable to initiate your triggers. Before the variable changes, there is no monitoring of what is typed.

Alexandra Angelova

Thanks everyone for your responses and sorry for reacting so late: I had put this project on hold for a short while and just got back to it.  

I tried Zsolt's hack and it does work for me, but I still need to play around some more to see how I can make it detect character numbers and/or key words. 

 

Adam Zamczyk

Hi Alexandra,

I don't know how to update the variable while typing, but I have used some javascript to check a number of characters in the text variable. I hope this will be useful 

every line of code has the description so it should be easy to understand what the code is doing step by step

You need a few variables 

- Length
- TextEntry
- this code check if the variable text has 8 or more characters

-------------------code below-----------------

//First, let's establish communication with Storyline:
var player = GetPlayer();

//Then let's reset our variables:
player.SetVar("Length",0);

//Then let's get the text from the TextEntry field. The text entry field in Storyline will need to use a variable called TextEntry:
var pw = player.GetVar("TextEntry");

//Then we'll store the value of the TextEntry in a JavaScript variable called str:
var str = pw;

//Then we will check if the TextEntry has 8 or more characters and if so, we will change the Storyline variable Length to correct value:
if (str.length >= 8) {
player.SetVar("Length",1);
}
else if (str.length < 8) {
player.SetVar("Length",-1);
}
else if (str.length = 0) {
player.SetVar("Length",0);
}

----------------- end of code----------

this code needs to be triggerd somehow, end it will check and change the Length variable to 1, -1 or 0. And you can have another trigger when variable Length changes, if 1 this, if 0 this, if -1 this...