Script doesn't work if I Publish entire project.

Jun 19, 2020


I'm trying to use script for changing variable if user press any key except Alt or =.

Script looks like this:

var player = GetPlayer(); 
function testKey(e) {
var isPressed = ((e.which == "187") || (e.which == "18"));
console.log("isPressed:["+ isPressed +"] e.which:["+ e.which +"]");
if (isPressed == false) { player.SetVar("KeyPressed_WrongKey", 1) }
e.which keycodes:
187: =
18 : Alt

 If I'm testing this on single slide, there is ok. But if I publish entire project, variable  KeyPressed_WrongKey changes even if isPressed == true.

Why it works like here?

There is any methods to change variable in StoryLine if user press a key except adjusted?


1 Reply
Sam Hill

Hi Tatiana, looking at your code, I see the variable KeyPressed_WrongKey should only be changing value if isPressed == false. Are you sure that there is not anywhere else in SL file that is changing the KeyPressed_WrongKey value, maybe on a Master Slide. Check the variables and look at the count next to the variable to see if it is used anywhere else.

Also, just in case you haven't come across this already. If using the trigger looking for a variable change, changing from "1" to "1" will not trigger. So, if needing to test from slide to slide, you may in some instances need to reset your variable KeyPressed_WrongKey to "0" on timeline start, so that you can then trigger and evaluate when it changes to "1" again. Does that make sense? Otherwise the value of "1" will be persisted from the first time it is set.

This discussion is closed. You can start a new discussion or contact Articulate Support.