Forum Discussion
Help with text questions
Joe referenced your problem with the variables, but here's a more detailed explanation.
You are using two variables to do the work of one, and they are not collaborating well. Consider what could happen. The learner makes a valid entry. The JS sets Q1_Valid to true, and all works well. Then on the next question, they make an invalid answer. The JS sets Q1_Error to true, but doesn't change Q1_VALID, so now they are both true. You can see how confusion as to which path to follow would ensue.
Additionally, If Q1_VALID is true, and the JS determines the answer is valid, it sets Q1_VALID to true and passes it back to SL. But SL doesn't consider setting a true variable to true as a change, so that trigger doesn't fire. What you need for the .story, and the JS is one variable, like Q1_VALID. Then have the JS set it as either true or false, and use that in your conditions.
There are two things you can't predict. One is what the variable is from the previous slide, and the other is what the learner will do with it. So you can never predict if it will change or not. For that reason, you need to attach decisions (triggers) to actions you know will occur. "When user clicks Submit" is a good choice; in this instance, "When variable changes" is not.
Joe's comment about global variables means that once you set a variable, it will have that value forever, unless you change it. So you need to be careful if you use the same variable for different functions, like checking if different answers are valid. There is always a danger you will be using a value left over from a previous slide.
In this case, you can get away with it if you change your JS to:
if (Q1_INPUT.length < 50){
player.SetVar("Q1_VALID",false);
} else {
player.SetVar("Q1_VALID",true);
}
If you do that and always execute the JS before you check the value of Q1_VALID, the JS will always set it correctly.
Any questions, please ask.