roguetrooper 2 Posted October 6, 2013 (edited) Example: A multiplayer game with three playable soldiers: p1, p2 and p3. p1 is not present (not as a player and not as AI) There is a script with if (player == p1) then { code1 }; if (player == p2) then { code2 }; if (player == p3) then { code3 }; As soon as a non-existing object appears in a script, you have the black error message. Even for if (isNull p1) then { }; Why does a command that is meant to check the existence of an object return an error-message when the object is not existing? So is there a way to avoid error messages caused by non-existing objects?? Edit: There is no error message when you use if (isNil "p1") then { hint "p1 does not exist" }; if !(isNil "p1") then { hint "p1 exists" }; The problem is that it still returns "existing" when the objects gets deleted (object, vehicle or non-playable unit) :-/ Edited October 6, 2013 by RogueTrooper Share this post Link to post Share on other sites
2nd ranger 282 Posted October 6, 2013 Try this before your code if (isNil "p1") then {p1 = objNull}; Share this post Link to post Share on other sites
nimrod_z 8 Posted October 6, 2013 if your just trying to run code for players, how about "isPlayer" command. if (isPlayer p1) then { needed code }; Share this post Link to post Share on other sites
Larrow 2822 Posted October 6, 2013 As soon as a non-existing object appears in a script, you have the black error message. Even forCode: if (isNull p1) then { }; Why does a command that is meant to check the existence of an object return an error-message when the object is not existing? Because it is not checking that the object is non existing, it is checking that the variable is null (referencing nothing) but the variable its self does not exist so you get an error. if ( !(isNil "p1") && {!(isnull p1)} ) then {hint "Player P1 exists"; }; If the variable p1 exists then check that its not null, if so p1 exists (the referenced object could be dead or alive). if ( !(isNil "p1") && {!(isnull p1) && alive p1} ) then {hint "Player P1 exists and is alive"; }; If the variable p1 exists then check that its not null and that the object p1 references is alive. The part of the IF statement contained in curly/code braces is NOT evaluated if the first part is not true. Share this post Link to post Share on other sites
roguetrooper 2 Posted October 6, 2013 Thanks to everybody. I've been looking for so long how to check (by script, not by trigger) for the existence of an object without generating an error message. Larrow's solution is just perfect. Thank you. Share this post Link to post Share on other sites