Generate random values for different instance

Get help using Construct 2

Post » Wed Aug 21, 2013 12:55 am

Hi !

I have an enemy and i want that each of his instance has a random fire rate. And i want that the fire rate has a new value after every shot.
I don't understand how do to that and with what.
Can you help me ?
I am searching since one week now and i did'nt find anything...
B
7
S
1
Posts: 30
Reputation: 787

Post » Wed Aug 21, 2013 1:04 am

random(x)
Generate a random float from 0 to x, not including x. E.g. random(4) can generate 0, 2.5, 3.29293, but not 4. Use floor(random(4)) to generate just the whole numbers 0, 1, 2, 3.

after shot > set firerate variable to random(max firerate). I assume you can use +300 if you don't want it to start from 0-max but instead something like 300-max. i haven't needed to use this stuff much in C2 yet.
B
46
S
16
G
73
Posts: 2,084
Reputation: 43,677

Post » Wed Aug 21, 2013 1:22 am

you can also

random(10,20)

if you want, for example, random a number between 10 and 20 =P

also. read the manual xD
B
43
S
12
G
6
Posts: 446
Reputation: 6,802

Post » Wed Aug 21, 2013 2:31 am

Thanks for your answer.
But I know how to generate a random value -_-"
I don't know how to generate it for each instance of the same object.
I have an enemy with many instance of him and i want that each of them have a different fire rate.
I can do something like :
Every random(1,4) seconde -> Create Object Bullet.
But this will choose a fire rate for ALL of the instance of my enemy and i don't want that. I want to generate one different for each of them.
B
7
S
1
Posts: 30
Reputation: 787

Post » Wed Aug 21, 2013 2:46 am

ImageImageImage
B
71
S
21
G
230
Posts: 3,688
Reputation: 128,847

Post » Wed Aug 21, 2013 3:02 am

I'm not able to look at capx files, so this might be already cleared.

You effectively answered your question yourself: "I don't know how to generate it for each instance ..."
That's the key. Just use the system condition "For each"
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279

Post » Wed Aug 21, 2013 4:11 pm

It works. Thanks a lot.
I knew the "For each" condition but not the Timer Behavior.
<3
B
7
S
1
Posts: 30
Reputation: 787


Return to How do I....?

Who is online

Users browsing this forum: Bootfit, grigrizljac, korbaach and 21 guests