Jump to content
Sign in to follow this  
roguetrooper

Error messages by isNull and isNil

Recommended Posts

When I perform the check

if (isNull objectname) then { }
or
if (isNil "objectname") then { }

then in the file arma2OA.RPT an error message line is created:

Error: Not defined variable in expression: <objectname>

The problem is, though it has no influence on ingame functionality, that this error message creates a rpt-file of hundred thousands lines when the map runs a while since the check is performed in an endless loop quite often for many objects.

How can this check cause an error? I mean, it is MEANT to check the existence of an object. Why does the check for existence cause an error when the object is not existing? :confused: and :mad: At this step within the script the object in question is not used for anything yet, it is just "looked at".

Is there a (scripting) way to check for the existence of objects that does NOT cause an error line in the rpt-file, no matter if the object exists or not?

Edited by RogueTrooper

Share this post


Link to post
Share on other sites

^ If you don't wrap the name of the variable in quotes, then it will instead read the value of the variable itself. If that variable is a string or code, then the command will use that string or code held by the variable. Example:

_myvar = "_hisvar";
isnil _myvar;
//will return true if _hisvar is null
_myvar = {tank1};
sleep (random 50);
isnil _myvar;
//will return if tank1 is nil, at the time the isnil command is checked (not at the time _myvar is established)

from isNil reference comments.

you should use isNull for objects. Also, make sure you are testing the object not its name as "string"!

Share this post


Link to post
Share on other sites

I have read the according wiki pages before and their explanations are quite theoretical.

As I said, ingame the check works fine and as intended and there is NO error message.

I only want to prevent that stupid error line in the rpt-file which gets bigger and bigger while the map is running.

When I use if (isNil "objectname") then { } while the object IS existing, there is no error line.

When I use if (isNil "objectname") then { } while the object is NOT existing, there IS an error line. In both cases the activation { } is performed properly.

I only want to get rid of the rpt-error-line.

Share this post


Link to post
Share on other sites

why not just use isNull wich is meant for checking objects?

isNil is for strings, any special reason you need to use it, or cant use isNull?

Share this post


Link to post
Share on other sites

_exist=false;
if (!isNil "objectName") then
{
if (!isNull objectName) then
{
	_exist=true;
};
};

Of course, it would probably be better to define the variable to objNull at the start of the mission, and then update it as needed.

Note that the variable will be nil if it was never assigned a value, while it'll be null only if it was either assigned the objNull value or if the object it was referring to have been deleted.

The error you're getting is because you're checking whether or not the object stored in the variable exists, while the variable itself doesn't exist. You can't check if a variable points at an actual object if the variable is not even defined as anything at all.

Share this post


Link to post
Share on other sites

isNil checks for variable/object reference

while isNull checks for existance of actual object

you can apply isNull only if the variable reference exists

otherwise you get the error as expected and you are seeing

Share this post


Link to post
Share on other sites

So seemingly there is no way to prevent the file arma2oa.rpt to have an error-line added each time the game checks for the existence of an object that is not existing?

You might want to reproduce my issue:

[1.] Clear the file arma2oa.rpt

[2.] Place two soldiers onto an empty map. Name them player1 and player2

[3.] Script a loop:

#start

~1.0

_exist1 = false;
_exist2 = false;

if (!isNull player1) then { _exist1 = true };
if (!isNull player2) then { _exist2 = true };

hint format ["check1: %1\ncheck2: %2", _exist1,_exist2];

goto "start";

[4.] Run the map a few seconds

[5.] Open the file arma2oa.rpt

When you have set player2 as non existing (0%) in the editor, the file arma2oa.rpt has a set of lines added each second:

(German version)

Error in expression <if (!isNull player2) then { _exist2 = true };>
 Error position: <player2) then { _exist2 = true };>
 Error Nicht definierte Variable in Ausdruck: player2

When you have a lot of things in your map that are not present all the time and have their existence checked every second, you have an inflated arma2.rpt with ten/hundred thousands of lines after an hour gameplay or so.

Share this post


Link to post
Share on other sites

You need to try to grasp the difference between the two commands.

Of course it errors if there is no variable player2.

You cannot apply commands on non existent variables/references.

Share this post


Link to post
Share on other sites

You're also mixing up SQF and SQS in that above code, use one (SQF...) or the other, not both. :)

Share this post


Link to post
Share on other sites

I might need to rephrase my question.

1. You want to check if an object is existing, since you can not predict if the object will exist at a certain point of time. You need to know if it exists, since something else depends on the result.

2. Therefor you need a command that checks the presence of an object.

3. This command can return two values: true (object is existing) or false (object is not existing)

4. Why then does this command, which is meant to tell you either "yes, object is existing" or "no, object is not existing" come up with an error message, when the object is not existing? The non-existence is a possible/logical result of the check. The non-existence is not a logical (or whatever) error.

I understand that there might be an error message when you want to place a non-existing 'player2'

player2 setpos [x,y,z]

since 'setpos' can not apply coordinates to something that does not exist. I understand that commands at all that need an object, return an error when they are confronted with a non-existing or invalid object.

But I really fail to see the logic for

"tell me if object exists" ---> "beeeep! error! object not existing"

That's the decicive point here for me.

I might be too penetrant on this issue... but that's what a forum is for :D

Share this post


Link to post
Share on other sites

The errors are because you have all of those SQF-ish semi-colons. Remove those and the SQS errors you're getting in your RPT will go away. SQF code ends each line with a ";" SQS however doesn't.

Share this post


Link to post
Share on other sites

Assuming the code is sqs:

#start

~1

_exist1=false
_exist2=false

?!isNil "player1":_exist1=true;if (isNull player1) then {_exist1=false}
?!isNil "player2":_exist2=true;if (isNull player2) then {_exist2=false}

hint format ["check1: %1\ncheck2: %2",_exist1,_exist2]

goto "start"

isNull only checks if a variable is null, either because it is set or a unit that was assigned to it doesn't exist anymore. A variable stays nil if the unit that would use it never came to be.

Share this post


Link to post
Share on other sites
The errors are because you have all of those SQF-ish semi-colons. Remove those and the SQS errors you're getting in your RPT will go away. SQF code ends each line with a ";" SQS however doesn't.

Most of the script files I create, ARE sqf and thus, containing sqf-stuff (colons and 'if' and such)...

Share this post


Link to post
Share on other sites

you cannot use goto commands in sqf, use loops instead, like while, for or foreach.

and if is for sqf, ? is for sqs, same as then is for sqf and : is for sqs.

asuming its .sqf file and is called with execVM

while {({!isNull _x} count [player1,player2]) != 0} do {
sleep 1.0;

_exist1 = false;
_exist2 = false;

if (!isNull player1) then { _exist1 = true };
if (!isNull player2) then { _exist2 = true };

hint format ["check1: %1\ncheck2: %2", _exist1,_exist2];
};

This works fine, no .rpt errors, and will run as long as there is atleast 1 of the units present, replace

({!isNull _x} count [player1,player2]) != 0

with true or any other condition to determine how long to run the loop.

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  

×