Random Subtraction

For questions about using Classic.

Post » Sat Mar 19, 2011 1:09 pm

I'm making a shooting game and all I need to know is how to set the damage (which is a private variable) of the bullet to be randomly chosen between two numbers.
eg. I want my pistol to deal damage anywhere between 1 and 10 how would I do this?
Nothing goes unanswered!
B
22
S
5
G
1
Posts: 430
Reputation: 3,383

Post » Sat Mar 19, 2011 1:38 pm

Use this at the subtract on your pvt variable

random(10)

Then to keep it from going lower

Compare pvt variable : less or equal to 0 / set pvt variable to 1
B
22
S
3
G
6
Posts: 1,356
Reputation: 7,141

Post » Sat Mar 19, 2011 1:41 pm

You can use the Random(x) expression to get a random number. To get a number within that range, you would subtract from your private variable -- using the subtract from private variable action -- this expression:

Random(10) + 1

One thing to know about the Random(x) expression is that it returns one of x possible numbers, from 0 up to, but not including, x. So Random(10) will return a value in the range of 0-9. Thus, adding 1 to this will bring the minimum up to 1 and the maximum to 10.
Moderator
B
98
S
37
G
19
Posts: 1,584
Reputation: 17,817

Post » Sat Mar 19, 2011 1:53 pm

Aah i forgot about the +1 at the end.
B
22
S
3
G
6
Posts: 1,356
Reputation: 7,141


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests