Forum Discussion

NeilZielsdorf-8's avatar
NeilZielsdorf-8
Community Member
4 years ago

Use Javascript to Control Slide Navigation

Hi all,

 

I am working on creating training that responds to API calls. So to better handle this I am writing a JS snippet that uses a switch to send a value to a variable to SL.


switch (stateId, eventIsValid) {
case 'stateId1', 'eventIsValid1':
branch = 1;
break;
case 'stateId2', 'eventIsValid2':
branch = 2;
break;
default:
error = true;
}

player.SetVar("branch",branch);


Then in SL I have triggers set to jump to a slide based on the value of "branch."
I do not like having the behaviour of my code broken into two different areas.

There there any way to add a JS command to jump to a specific slide into my switch?
Essentially, I want the code to look like this:


switch (stateId, eventIsValid) {

case 'stateId1', 'eventIsValid1':
console.log(stateId2, eventIsValid1);
player.JumpToSlide(1.2);
break;
case 'stateId2', 'eventIsValid2':
console.log(stateId2, eventIsValid1);
player.JumpToSlide(2.3);
break;
default:
error = true;
}
player.SetVar("error",error);

2 Replies

  • I'm interested in how you managed to get a slide switch thanks to JS, would you mind contacting me if it works now ?

  • Hi, Anne-Laure!

    Neil might not be subscribed to this discussion, but you're welcome to contact them directly through their profile by clicking on their name and selecting Contact Me

    I hope this helps!