How do I random player selecting ???

Get help using Construct 2

Post » Thu May 22, 2014 3:24 pm

gi,
i have for example same player character with 3 color
i want that every start of new player , the player change color randomly !!!! how i do it ?
thanks
B
45
S
16
G
8
Posts: 792
Reputation: 8,306

Post » Thu May 22, 2014 4:34 pm

Like with most "How do I" questions, there are a lot of ways to accomplish this. However, here is a way that will absolutely minimize the number of actions you need.

1 - Create a variable (it should be an instance variable on the character but my example has it global so you can see it in the event sheet)
2 - Create your event where the change should happen
3 - In the action, set the global variable using the following expression: round(random(2))
random(2) chooses a random decimal number between 0 and 2, not including 2 and round() rounds it to an integer. Because you are rounding, you will get the number 2 even though random doesn't include 2. This is important in a later step.
4 - Set all your animations to be the same name with a 0, 1 or 2 at the end (ie: idle0, idle1, idle2) and make sure the number corresponds to the color (all blue animations use 0 etc...)
5 - when choosing the animation set it to the base name & number (animation = "idle" & animationNumber). The & sign combines strings so if animationNumber = 1 it turns this example into "idle1".

That's all. See the attached example for a simple use.

I hope that helps you and good luck with your project.
You do not have the required permissions to view the files attached to this post.
Last edited by FragFather on Tue May 27, 2014 2:17 pm, edited 1 time in total.
B
39
S
12
G
11
Posts: 331
Reputation: 7,727

Post » Tue May 27, 2014 2:04 am

thanks a lot
B
45
S
16
G
8
Posts: 792
Reputation: 8,306


Return to How do I....?

Who is online

Users browsing this forum: Kermad, lukewasthefish, marc254, tarek2 and 15 guests