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
Really nice Jonathan, one question and probably because I don't use dials very much, could you not get perpetual potion by setting to 360 and then add a trigger to change value of the variable to 0 when it is 359 or is that bad practice
and I answered my own question it doesn't work, and that must be a bug
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.
I am sure that used to work when it was flash based
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
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.
Hi Jonathan. Thanks for sharing this really nifty solution. Also, I know it's just a small detail, but the little dial-turning sound effect you used makes the whole thing feel extra realistic.
Thanks Bianca. All of the sound effects are CC0 from Freesound.org. I'm a heavy user and regularly donate to keep the platform going.
Pretty much any sound you can think of, want, or need is there.
Excellent - thanks