Game Development Community

Trap an error ??

by Michael Schaumburg · in Torque Game Engine · 12/10/2002 (4:57 am) · 4 replies

I am using the following code to get the closest player to the NPC:
%count = ClientGroup.getCount();
	for(%i = 0; %i < %count; %i++)
	 {
		%client = ClientGroup.getObject(%i);
            	%playPos = %client.player.getPosition();
........
........
If the engine isn't completely ready or the player isn't ready to start, I get an error message in the console: Unable to find object.... when the function %client.player.getPosition is called.
If you check the var %count you get 1 if there is one human player. The var %client givers you the id of the corresponding object. How can I prevent the error in the getPosition function? The console.log file is getting bigger and bigger. The same happens, when the player was killed until the new one is created.

#1
12/10/2002 (5:05 am)
Hm, guess I can help you again... doh! :P
You can simply do
if(isObject(%client))
{
   // whatever
}
#2
12/10/2002 (8:30 am)
I think it must be like this
%client = ClientGroup.getObject(%i);
if(isObject(%client.player))
{
........
........

My problem is, that I don't know all the commands and functions, sorry Stefan you are my great teacher....
#3
12/10/2002 (9:11 am)
if(isObject(%client)) will work too...
#4
12/10/2002 (9:22 am)
In this situation it needs to be if(isObject(%client.player)), sorry.