choose random anim

Get help using Construct 2

Post » Sun Oct 06, 2013 11:52 pm

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.
B
5
S
1
Posts: 92
Reputation: 609

Post » Mon Oct 07, 2013 12:39 am

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

Sub Event : Cond: Var = 1     Set Animation "Muzzle 2"
B
46
S
16
G
74
Posts: 2,089
Reputation: 44,187

Post » Mon Oct 07, 2013 1:11 am

set animation to "Muzzle "&int(random(1,3)))
Image ImageImage
B
169
S
50
G
170
Posts: 8,292
Reputation: 108,728

Post » Mon Oct 07, 2013 1:14 am

You can also use choose("muzzle1", "muzzle2")
B
46
S
14
G
7
Posts: 603
Reputation: 8,116

Post » Mon Oct 07, 2013 1:56 am

[QUOTE=EncryptedCow] You can also use choose("muzzle1", "muzzle2")[/QUOTE]

This one sounds more interesting. But throws a syntax error saying that the coma can't go there.
B
5
S
1
Posts: 92
Reputation: 609

Post » Mon Oct 07, 2013 2:14 am

check Caps
B
12
S
3
G
1
Posts: 347
Reputation: 2,866

Post » Mon Oct 07, 2013 2:26 am

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.
B
46
S
16
G
74
Posts: 2,089
Reputation: 44,187

Post » Mon Oct 07, 2013 2:35 am

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.
B
5
S
1
Posts: 92
Reputation: 609

Post » Mon Oct 07, 2013 2:37 am

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.
B
5
S
1
Posts: 92
Reputation: 609

Post » Mon Oct 07, 2013 3:24 am

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.
B
46
S
14
G
7
Posts: 603
Reputation: 8,116

Next

Return to How do I....?

Who is online

Users browsing this forum: jorgmaquoi and 20 guests