choose random anim

0 favourites
  • 14 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • when my char shoots there's some muzzle flash.

    the flash is an sprite that's created with "create object" and destroyed once the anim is over.

    I have 2 animations for the muzzle and I want the sprite to choose randomly between those 2. let's call them "muzzle1" and "muzzle2".

    I made a global variable that randomly chooses 0 or 1 at everypick, but that makes the muzzle change all the time in the same sprite.

    What I want it to do is choose one of the 2 anims but only when it's created and stick to that anim until it's over.

  • Create Object

    Sub Event : Cond: Var = 0     Set Animation "Muzzle 1"

    Sub Event : Cond: Var = 1     Set Animation "Muzzle 2"

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • set animation to "Muzzle "&int(random(1,3)))

  • You can also use choose("muzzle1", "muzzle2")

  • You can also use choose("muzzle1", "muzzle2")

    This one sounds more interesting. But throws a syntax error saying that the coma can't go there.

  • check Caps

  • I think you can only choose numbers or strings. Using actual objects might not work, you may have to relate choose(1,2) to the different anims which kinda comes back to my original post.

  • the only thing that didn't bring a syntax error was this exact expression:

    ("muzzle1,muzzle2,muzzle3")

    (I'm using 3 animations now)

    but it doesn't do anything. it always plays the default animation.

  • I see.

    I was avoiding that cause it's a pain to create a variable only to choose a random anim which is something I'll do a lot. should be simpler. But it's ok.

  • That's very weird. choose("muzzle1", "muzzle2", "muzzle3") works perfectly fine for me. (@plinkie the only 2 types of values are numbers and strings) Also choose("muzzle1,muzzle2,muzzle3") should not work since it needs at least 2 parameters.

  • well, I put in in the box where you must write the name of the anim like this "muzzle1", in set animation.

    but if I write ("muzzle1","muzzle2","muzzle3") there, it says the coma is a syntax error.

  • I'm maybe a little late to the party, but this may be of use to you:

    scirra.com/tutorials/252/random-animation

  • Are you putting choose("muzzle1","muzzle2","muzzle3") or just ("muzzle1","muzzle2","muzzle3")? <img src="smileys/smiley17.gif" border="0" align="middle" />

  • Are you putting choose("muzzle1","muzzle2","muzzle3") or just ("muzzle1","muzzle2","muzzle3")? <img src="smileys/smiley17.gif" border="0" align="middle" />

    HA!!! that was it. Sorry. It works now. thanks!

    Also, the "choose" thing is much simpler and direct than all the stuff in that tutorial...

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)