Jump to content
Sign in to follow this  
Electricleash

IsNil and IsNull

Recommended Posts

Hi

Could somebody explain (in layman's terms) what these commands are used for, as I have seen them a lot in various peoples missions.

The description in the wiki is just to cryptic for me to get my head around.

Thanks

E

Share this post


Link to post
Share on other sites

isNil checks if a variable is defined:

_var = 5;
isNil "_var"; //returns false

isNil "_anotherVar"; //returns true because _anotherVar isn't defined

isNull can be used to check if a defined variable contains an object:

_unit = objNull;
isNull _unit; //returns true;

if(_unit == objNull).... //this wouldn't work because objNull isnt equal to anything even to itself

Edited by T_D

Share this post


Link to post
Share on other sites
Hi

Could somebody explain (in layman's terms) what these commands are used for, as I have seen them a lot in various peoples missions.

The description in the wiki is just to cryptic for me to get my head around.

Thanks

E

Good call. Sometimes, most of the time, the Wiki and ComRef are hard for me to understand. I was wondering the same thing a few days ago.

Share this post


Link to post
Share on other sites

Ok, you've been reading other peoples missions. So you are reading code.

This is a good way to learn.

However what you need to do is get your hands dirty, and write some code, and get some stuff wrong. You know there is a difference between isNil and isNull, so when one doesn't work, the other will. Trial and error is an important part of the learning process.

Because by the sound of it you have seen and read lots of examples in other peoples code. So by now you should have gotten a grasp.

If you are only ever going to read code, then frankly it doesn't matter if you understand, you're never going to need it.

_vehicle = "HMMWV" createVehicle position player;

_driver = driver _vehicle;

if ( _driver == objNull) {

// vehicle has no driver;

} else {

hint format["driver is %2",_driver];

};

_respawnTime=_vehicle GetVariable "RespawnTime";

if ( isNil "respawnTime") then {

// no respawn time defined

} else {

hint format["respawn time is %2",_respawnTime];

};

Its all about data-types:

"driver" will always return an "object" so it will be "an object" or "null" aka. no-object.

"getvariable" can return any type string/array/object/scalar or "unknown"

So I suppose the difference between isNil and isNull is the difference between "is unknown" and "is nothing".

Any wiser ?

BA

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  

×