random health substract

Get help using Construct 2

Post » Fri Dec 16, 2011 6:59 pm

Like in topic. When i hit opponent, random number is substracted from his hp variable. how do this?
B
93
S
19
G
34
Posts: 1,840
Reputation: 27,963

Post » Fri Dec 16, 2011 7:25 pm

use the random function.

for example if i want a random number between 1 and 100 -

random(100) this will return a random value from 1 -100
    - This will return a decimal value though.

If you want a integer(whole number) ---

int(random(100) -- Will return a whole number between 1 - 100
B
29
S
12
G
7
Posts: 740
Reputation: 7,849

Post » Fri Dec 16, 2011 7:32 pm

when i want substract 5-9 ?
B
93
S
19
G
34
Posts: 1,840
Reputation: 27,963

Post » Fri Dec 16, 2011 7:40 pm

Try -

int(random(5,10))
B
29
S
12
G
7
Posts: 740
Reputation: 7,849

Post » Fri Dec 16, 2011 7:41 pm



You want a range of 5 numbers: 5 6 7 8 9,
so get a random number between 1 and 5 and then add 4 to that number.

It would be something like:
4 + int(random(5))


I dont recall if random gives you a spread from 0 to the number, if that is the case you might have to do this:

5 + int(random(4))
gardnerp2011-12-16 19:43:00
B
17
S
3
G
6
Posts: 14
Reputation: 3,850

Post » Fri Dec 16, 2011 11:34 pm

Thank you so much this is very helpful!
B
93
S
19
G
34
Posts: 1,840
Reputation: 27,963


Return to How do I....?

Who is online

Users browsing this forum: Popcan151, spcsmrf and 15 guests