Forum Discussion
Is there a way to auto run some triggers in a loop until the results are met?
- 3 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.
You're running into a limitation: Storyline doesn’t support traditional loops or real-time conditional recursion, so using a button click to re-randomize each variable is about as close as you can get with built-in triggers and conditions.
While it's possible to handle this entirely within Storyline using triggers and conditions, the solution becomes clunky and difficult to scale if you have more than four variables. You would also end up with too many triggers, making it more complex to track and maintain. Additionally, this method introduces delays, as it relies on event-based triggers rather than true loops or real-time logic.
However, there's a cleaner workaround using a small JavaScript snippet. JavaScript can efficiently handle loops and ensure unique number generation and you can still pass those values back into Storyline variables. Let me know if you'd like help setting that up.
Related Content
- 7 months ago
- 4 months ago
- 10 years ago