Getting animation list

Speeder

  • Posts: 15
I want to set a character to a random animation upon creation...

But I do not figured how to get all available animations to do that.

Someone here has a clue?

rob1221

  • *
  • Posts: 9472
When editing an actor you can add more animations.  Then when the actor is created, you can set an attribute to a random number between 1 and x where x is your total number of animations.  Make if statements for each number of the attribute and set the animation based on that.

Speeder

  • Posts: 15
How I figure the total amount of animation?

Alexin

  • *
  • Posts: 3130
A common trick I've seen around here is to append a different number to each animation's name. Then, a behavior generates a random number that is appended to some text, which in turn is fed to the "switch animation" block.

For example, assume an actor has the following animations: "anim1", "anim2" and "anim3". A possible combination of blocks would be

[switch animation to [["anim"] + [random number between 1 and 3]]]
"Find the fun"
alexin@stencyl.com

Speeder

  • Posts: 15
Yes, I did that, and manually set the number of animations... I wish there was a automatic way though...

Miasmos Games

  • Posts: 878
Unfortunately there isn't at the moment (unless someone can come up with some code?) but one thing I might add is that if you want to keep names intact (i.e. not have to name things with numbers and so uniformly) you could do what I do, which is to create a list and populate it with the names of each animation, then set the animation to a random animation from the list using 0 and "number of items in list -1" as the variables for the random block :) Hope that helps (and is understandable) :P

Cupcake Bounce

coleislazy

  • *
  • Posts: 2607
I haven't tried this, but it may work:

Code: [Select]
_MyNumberAttribute = actor.anims.length;
You could replace "actor" with an actor attribute, as well.

Alexin

  • *
  • Posts: 3130
That won't work. The array of animations is acting like a map. You can get a random animation from the array, but to effectively make the switch the engine needs the name for other tasks. I browsed the source code, but couldn't find any way to do it without modifying the engine.
"Find the fun"
alexin@stencyl.com

coleislazy

  • *
  • Posts: 2607
If you named your animations 1-x, wouldn't getting the length of the anims array allow you to select a random animation between 1 and the length?

Alexin

  • *
  • Posts: 3130
Yes, it would. I just wasn't considering that trick. >_<
"Find the fun"
alexin@stencyl.com