PDA

View Full Version : IsNil and IsNull



Electricleash
Jul 26 2009, 23:27
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

T_D
Jul 26 2009, 23:37
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

Manzilla
Jul 27 2009, 00:05
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.

barmyarmy
Jul 27 2009, 18:14
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