# Random Subtraction

This forum is currently in read-only mode.
0 favourites
• 4 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
• 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?

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• 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

• 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.

• Aah i forgot about the +1 at the end.