FREE: Perpetual Dial

Mar 05, 2024

Spinning out of my work on E-Learning Challenge #453, here's my early entry for Challenge #454, Using Variables.

Try it for yourself here.

This demo uses Number, Text and True/False variables to trigger events based on the position of the dial.

But as you can see, this dial spins in both directions - seemingly forever* - overcoming one of the limitations of this interactive object.

I've achieved this by incorporating the following Javascript, which reports the position of the dial as 0-359° despite the dial having a rotation of 0-9360°.

// Function to calculate the position within the range of 0-359
function calculatePosition(dial) {
    // Calculate the position within the range of 0-359
    var position = (dial % 360 + 360) % 360;

    return position;
}

// Get the value of the Storyline variable Dial and calculate Position
var Dial = player.GetVar("Dial"); // Assuming "Dial" is the name of your Storyline variable
var Position = calculatePosition(Dial);

// Set the Storyline variable "Position" to the adjusted value
player.SetVar("Position", Position); // Assuming "Position" is the name of your Storyline variable


Download the file to see how it works, and please let me know if you have any questions.

* Try spinning it continuously in one direction - it'll take you a while to reach the end, but see what happens 😃

9 Replies
Jonathan Hill

Thanks!  That was one of the first things I tried, Phil.  But 'overwriting' the underlying variable when it reaches the start or the end position doesn't seem to have the effect of resetting the dial's position, oddly.  I also tried reloading the slide to achieve this, but no luck.

Jonathan Hill

Interestingly, it's a similar story with sliders, Phil.  A trigger to reset the slider variable when the slider reaches the end only changes the variable, not the slider's position.

Yet a when user clicks trigger - activated before the slider reaches the end - does reset both the underlying variable and the slider's position

Jonathan Hill

Closest I can get to it is this - a trigger timed to the entry animation on a hidden object, which becomes visible when the slider is ≥ 99 



It's a bit jerky for my liking.

Similar visual issues when I use the same method on a dial, and it also takes a moment for the change to take effect and you have to grab the dial again.