Jump to content
Sign in to follow this  
roguetrooper

isNil and error messages and triggers

Recommended Posts

Don't know where to put this.

[1.]

Why does the check in a script

if (isNil "object") then { } 

cause an error message when the object is not existing?

I understand that

object setpos [x,y,z];

causes an error message when the object is not existing. But why does a command that is supposed to return the existence or non-existence of an object cause an error message when the object is not existing?

[2.]

Triggers seemingly have an implemented protection against the -showscript error messages. When you execute

object setpos [x,y,z];

within a trigger while the object is not existing, there is no error message, but when you do the same within a sqs/sqf file, there is that black error message.

Share this post


Link to post
Share on other sites

Had the same problem in the past... my workaround:

if (isServer AND object in allMissionObjects "HOUSE") then {object setPos [x,y,z];};

;)

Edited by Buliwyf

Share this post


Link to post
Share on other sites

[1]

Just to clarify. What your trigger do is to check if the variable "object" has ever been set to a value or not. If you want to check if an object stored in your variable exists, use command isNull (isNull object).

Personally I wouldn't use "object", since it may be reserved in different ways, but maybe that was just your example...

Share this post


Link to post
Share on other sites

Thanks for your replies. But both isNull and isNil return a blackbox-scripterror-message when the object/variable have never been defined since mission start.

The error problems remains even with

if (isServer AND [b]object[/b] in allMissionObjects "HOUSE") then {object setPos [x,y,z];};

When object has not been defined yet, there is the error message.

My problem is that I need to check (within sqf-scripts) whether certain playable soldiers in a MP-map are present or not. Player slots can remain empty or players log in and out.

My workaround for this so far:

* the names of the playable soldiers placed in the editor are player1, player2 etc.

* in the init.sqs I define the variables

EXISTING1 = 0;

EXISTING2 = 0;

etc.

* for each playable unit I have a trigger:

repeatable
condition: (lifeState player1) in ["ALIVE","UNCONSCIOUS","DEAD"]
on activation: EXISTING1 = 1;
on deactivation: EXISTING1 = 0;

Using the condition "alive player1" is insufficient because a player that logs out, also triggers "not alive playerX". Only units that are present (dead or alive) can be have the lifeState "alive or unconscious or dead". lifeState returns false for not existing units WITHOUT causing a scripterror-message.

* When it is about implementing player1, player2 into my sqf-scripts, I use the goto-command to make the script not encounter a unit that is not existing and thereby causing a scripterror-message (do you understand what I mean? o_O )

e.g:

if (EXISTING1 == 0) then { goto "notexisting1" };
player1 setpos
player1 addweapon
etc.
#notexisting1

if (EXISTING2 == 0) then { goto "notexisting2" };
player2 setpos
player2 addweapon
etc.
#notexisting2

This is the only method I found out so far to bypass that annyoing not-defined-scripterror-problem. A trigger does not return a scripterror-message when it checks for a unit that might not have been defined at all since mission start.

Edited by RogueTrooper

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  

×