This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.
People sometimes want to use a random animation but want more options.
Firstly, props to Weishaupt, who wrote another very good tutorial here that explains a longer method of doing this, and I learned from it - you should check it out. Though eventually I found an even easier way to do this without any variables, random number generation or even math.
The "choose" command is just the word "choose" and then 2 or more parameters. Incredibly handy.
In this example:
the command will randomly pick one of the colors and return that text. You might get back the word "red" or the word "blue" or any of the other items you put in the list of parameters.
We simply combine this "choose" command with the Set Animation action. That is, when you want the new animation randomly chosen, just list which animations you want randomly selected from using the choose command like so:
Just substitute your animation's names. Use only the animations you want randomly chosen by putting them in the list.
Another thing you can do is give more weight to animations you want to see more often. So for example, if you want to see the animation named "Default" more often, then put it in the list twice (or more) like so:
The order of the animations in the choose list does not matter, a new one will be selected at random whenever your condition triggers.
from the Manual
choose(a, b [, c...])
Choose one of the given parameters at random. E.g. choose(1, 3, 9, 20) randomly picks one of the four numbers and returns that. This also works with strings, e.g. choose("Hello", "Hi") returns either Hello or Hi. Any number of parameters can be used as long as there are at least two.
This is so well written and just the right amount of information I needed to make a weighted random choice - Thanks a ton for this tutorial!
Thank you so much for this
Yo thanks ill put you in my games credits!
I was pounding my head against the desk until I found this. Thanks a lot. Saves loads of time.
Very helpful and easy to understand for even beginners. I appreciate you taking the time out to make this. Thank you.