Jump to content
Sign in to follow this  
niubbone

Define the min and max value of a variable

Recommended Posts

niubbone

I wasn't able to find in forum and in help too.

If I have a value let's say for a game, and let's call it $healt, then, how I set that variable minimum to for example 0 and maximum for example 100?

Then during the game it will be modified but it must never go under 0 or over 100.

I just control the $healt value modifying events with If or so (Like if $healt >=0 or <=100 then decrease it) or there is a way to make it value exceeding proof?

For example i may want to put fights and i have 20 healt left, but my enemy hits me for 30. I want it to stop at 0 because I told before that the value of $healt must not go under 0 or over 100.

Any clue?

Also, If you suggest/know different method of doing the same thing, post here.

Thanks community.

Share this post


Link to post
Share on other sites
MrMitchell

At key points throughout script or whenever necessary to check, you can do:

If $healt < 0 Then $healt = 0

or

If $healt > 100 Then $healt = 100

Something like that?

Share this post


Link to post
Share on other sites
niubbone

Yes that would work perfectly. Just wondering if there was a native function to state the thing when declaring a variable. Just asking to who knows more than me. Thanks, thats a good solution.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.