Forum Discussion

AaronBurgessAU's avatar
AaronBurgessAU
Community Member
3 months ago
Solved

Is there a way to auto run some triggers in a loop until the results are met?

I have a project with 4 objects that need to appear randomly in 1 of 4 rows. I've set up a test slide where I generate a number between 1 and 4. At the moment if A and B are the same number I have ...
  • Nathan_Hilliard's avatar
    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.