Forum Discussion
Is there a way to auto run some triggers in a loop until the results are met?
- 5 months ago
JavaScript is more elegant and efficient, but for a few variables, you can do it with a handful of triggers on a layer.
Demo: https://360.articulate.com/review/content/041f67c6-c44a-47e8-a301-632caa78772b/review
This just shows a layer that assigns 4 random numbers to 4 variables. If any are the same, it reruns the the layer until they are all unique. This is very brute-force, but very simple. The triggers are fast enough that even if it takes many attempts, it is still practically instant.
This could be modified with a few more triggers to be more elegant, recalculating each random number only if it matches one of the previous variables, but in the end it is essentially the same thing. Simple gets the job done.
As Nedim mentioned, if you try this with many variables, it could begin to slow down, or require too many triggers. In that case, JavaScript is the way to go.
The trick to continuous loops is using toggle. If valueB is good, toggleC, else toggleB again.
But, it's much easier to do this task using javascript.
I made a row of 4 circles and displayed a variable in each: %circleA%, %circleB%, etc. These variables were text, so the same solution would work if you were randomizing fruit names or anything else.
Then attach this javascript either on page load or button click.
// Define your list as a JavaScript array
var myList = ["1", "2", "3", "4"];
// Fisher-Yates Shuffle Algorithm
for (let i = myList.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[myList[i], myList[j]] = [myList[j], myList[i]]; // Swap elements
}
// Update Storyline variables
var player = GetPlayer();
player.SetVar("circleA", myList[0]);
player.SetVar("circleB", myList[1]);
player.SetVar("circleC", myList[2]);
player.SetVar("circleD", myList[3]);
Related Content
- 10 months ago
- 10 months ago
- 10 years ago