Forum Discussion
JavaScript and variable updating
I have a project with about 125 slides which have about 10 layers each. Each layer has two dials. I have a lot of dials. The slides are roughly in two groups. One group is a practice and one group is a procedure. Each practice has an exact procedure slide, but some of the steps have been changed. Ex. Slide 1A (Practice) and Slide 1B (Procedure) are identical in triggers, images, variables, and layer names.
I have had to duplicate my A slides to make B slides. Since I do not want my dials to start off of the 12 o'clock position I have "Adjust Dial 1001 to value 1 when the timeline starts on this layer." This is the trigger for the first dial on Slide A.
I want to have the same trigger on the first dial on slide B. All of the triggers stay the same, but the dial has a new variable.
Can a JavaScript program be created to automatically adjust the triggers to equal the variables?
Would this script have to be entered into each layer?
3 Replies
- Dave-RuckleyCommunity Member
I'm assuming you want the dial on slide B to match the value of the dial on slide A? If so I'd have a true/false trigger called something like "runscript". I would also rename all the dial variables to be something like Dial1001A, Dial1001B, Dial1002A, Dial1002B etc, and this code will do what you want:
var player = GetPlayer();
// List of variable pairs
var variablePairs = [
["Dial1001A", "Dial1001B"],
["Dial1002A", "Dial1002B"]
// Add more pairs here if needed
];// Copy values
variablePairs.forEach(function(pair) {
var fromValue = player.GetVar(pair[0]);
player.SetVar(pair[1], fromValue);
});
and have that run on the base layer with the trigger Run Javascript when runscript chages. Then on the B Slides have 2 triggers, one to set runscript to true when the timeline starts on that slide and then one to change it back to false when timeline reaches 1 second.
There's probably a more elegant way to do it but this should do what you're asking. See the attached file to see it in action. - DavidNowlin-f8aCommunity Member
Thank you for your reply. I am more interested in renumbering the variables in the triggers to match the variable number of the new dial. The problem with just using the initial value, for this project at least, is if the learner replays the slide. The learner has a Replay button that has a Show Layer trigger. Since the learner does not leave the slide, the dials do not reset by the Initial Value setting alone.
- JudyNolletSuper Hero
I don't know of a JavaScript program that can do what you're asking.
I did want to point out that you don't need a trigger to adjust a dial's starting position. That is determined by its Initial Value.
The default when you insert a dial is to have it range from 0 to 12. The default Initial Value is 6, which puts the pointer in the vertical position. To change the starting position, just edit the Initial Value.