Like in topic. When i hit opponent, random number is substracted from his hp variable. how do this?
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
Develop games in your browser. Powerful, performant & highly capable.
when i want substract 5-9 ?
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))
Thank you so much this is very helpful!