Jump to content
Sign in to follow this  
thetrooper

if/else problem

Recommended Posts

Hello. I'm having trouble with my if/else statement. Any reason why it's not working?

if (

(damage civ4)<0.8;

) 

then {

_null = [west, "tskobj_4", ["Locate and destroy technical vehicles", "Destroy Vehicles", "Vehicles"], [], true] spawn BIS_fnc_taskCreate;

} else {

null = [west, "tskobj_3", ["Treat the man", "Treat Injured (Optional)", "Treat"], "obj_3", true] spawn BIS_fnc_taskCreate;

};

Share this post


Link to post
Share on other sites

The brackets have to encompass the entire condition in the if statement

---------- Post added at 16:07 ---------- Previous post was at 16:06 ----------

The brackets have to encompass the entire condition in the if statement

if (

(damage civ4)<0.8

)

Edited by Tankbuster

Share this post


Link to post
Share on other sites

if ( 

(damage civ4)<0.8 

)  

then { 

_null = [west, "tskobj_4", ["Locate and destroy technical vehicles", "Destroy Vehicles", "Vehicles"], [], true] spawn BIS_fnc_taskCreate; 

} else { 

_null = [west, "tskobj_3", ["Treat the man", "Treat Injured (Optional)", "Treat"], "obj_3", true] spawn BIS_fnc_taskCreate; 

}; 

- removed ; in condition

- added _null for the second function call

I haven't checked the parameters for BIS_fnc_taskCreate.

greetings Na_Palm

Edited by Na_Palm
typo

Share this post


Link to post
Share on other sites

The _null thing isn't really necessary anyway. It makes sense inside the editor, because the engine won't allow unbound return values from init calls or whatever else. i.e., we do it as a convention to suppress the error and name the variable _null or _nil because it is immediately discarded by the game anyway.

If you're inside of a script, you are actually binding the variable _null which is treated like any other machine-local variable. This breaks another convention because we generally use underscore (_) to denote a variable local to a particular script, and declared with "private" in the scope where it is used.

If you don't need the value, don't assign a variable if you don't have to :)

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  

×