Jump to content
Sign in to follow this  
Bangomango

Possible screwup on If/then statement or number comparison

Recommended Posts

In the editor I have a civilian doctor with the name "Doctor". He has an action called "Check Doctor's health" which corresponds to my dochealth.sqs file. Here are the contents of the .sqs file:

if ((damage Doctor)==0) then {hint "Doctor is in perfect health";};

if (0<(damage Doctor)<.25) then {hint "Doctor is in good health";};

if (.25=<(damage Doctor)<.50) then {hint "Doctor is in fair health";};

if (.50=<(damage Doctor)<.75) then {hint "Doctor is in poor health";};

if (.75=<(damage Doctor)<.90) then {hint "Doctor is in very poor health";};

if (.90=<(damage Doctor)<1) then {hint "Doctor is at critical health";};

The "Doctor is in perfect health" works fine.

However, when I am damaged and do the action, no hint pops up.

Am I formating the number comparison wrong, where it can only have two sides, or am seperating the if/then statements incorrectly.

Thanks.

Share this post


Link to post
Share on other sites

_dam = getdammage doctor;
if (_dam==0) then {hint "Doctor is in perfect health";};
if (_dam < 0.25) then {hint "Doctor is in good health";};
if ((_dam > 0.25) and (_dam < 0.50)) then {hint "Doctor is in fair health";};
if ((_dam > 0.5) and (_dam < 0.75)) then {hint "Doctor is in poor health";};
if ((_dam > 0.75) and (_dam < 0.90)) then {hint "Doctor is in very poor health";};
if ((_dam > 0.9) and (_dam < 1)) then {hint "Doctor is at critical health";};

ps. dont do this as file *.sqs . make it *.sqf

sqs is is the old scripting language. sqf is better.

Edited by nuxil

Share this post


Link to post
Share on other sites

Btw, a nested if/else system (doesn't look too good) or a switch(true) do {} system (looks best) would be more efficient, as nuxils code still checks the rest of the ifs (which isn't needed if a hit was found).

Probably not something to worry too much about if it's a unique event, but in a complex loop it's always nice to try to be as efficient as you can.

Share this post


Link to post
Share on other sites

just showing him how the correct syntax of the if statement would look like.

and yes, it looks ugly. i would not do that im my own script

Share this post


Link to post
Share on other sites

Btw2, a unit dies I think at any damage above 0.9 (but not including 0.9). So

hint "Doctor is at critical health" should probably read

hint "Doctor needs a coroner" :p

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×