Counting hits with random value. Random not working here

Get help using Construct 2

Post » Mon Aug 07, 2017 3:45 pm

I'm counting hits that my object taken from towers. If this number is = 0.6 I do something.
I have action: Add random(0.3,0.6) to hited(obj. variable)
And system not gather random values. When I changed for one number "0.6" system counting properly.

Is "random(0.3,0.6)" is correct value?
B
10
S
4
G
2
Posts: 165
Reputation: 2,316

Post » Mon Aug 07, 2017 4:26 pm

From the manual:

"random(a, b)
Generate a random float between a and b, including a but not including b."

This means that:
Random(0.3 , 0.6) can be 0.3 or more than 0.3.
but it can't be 0.6. It can at most be 0.59999999 (or something like that, I don't know how precisely random operates.)
B
6
S
2
G
2
Posts: 33
Reputation: 891

Post » Mon Aug 07, 2017 4:34 pm

If you want a value that goes from 0.3, to and including 0.6, I recomend this expression instead:
0.3 + floor(random(31))/100.
The "Floor" expression rounds of the number downwards;
30,999->30.
0,7345->0.
25,456->25.


The /100 converts the number into the appropriate potence. (30/100=0.3)
B
6
S
2
G
2
Posts: 33
Reputation: 891


Return to How do I....?

Who is online

Users browsing this forum: mindragon73 and 22 guests