Game Development Community

Trigger onEnter gets wrong obj

by Hogie · in Torque 3D Professional · 05/17/2010 (12:48 am) · 11 replies

Okay, so it seems all of the triggers, custom and stock, in my level are not getting the proper %obj. By this I mean, the function ::onEnterTrigger(%this, %trigger, %obj) is not using the object that actually entered the trigger. In my level, the player's current object ID is 3658. If I use echo to inquire which object entered the trigger, it returns 3661. I know object ID changes, but it doesn't seem to be recognizing my player object. Anyone have any ideas??

#1
05/17/2010 (2:58 am)
It seems to be working for me. Try to put an echo in your trigger returning the player ID
echo(%obj);
Then remember that there is a difference between the client's ID and player's ID. Plase your trigger in your map and walk through it, it will return a random number. Then enter the world editor and press alt+c, select your player and look at the ID field, it should match what returned in the console. If not, there is something wrong somewhere else.

Tell me if it works for you.
#2
05/17/2010 (3:55 am)
I usual give my players/ai names to avoid the "guess the ID game" that Marcus mentions above.

function myTrigger::onEnterTrigger(%this,%trigger,%obj)
{
%checkclass = %obj.getclassname();
   if(%checkclass $= "player")
	{
		echo(%obj.getname() @ " is the player with ID of " @ %obj.getID());

	}
	else
	{
echo("NOT player in trigger - must be an AI");
	}
   Parent::onEnterTrigger(%this,%trigger,%obj);
}
#3
05/17/2010 (4:09 am)
I was actually not suggesting guessing the ID =/. As i understood this question, he's player's ID does not return correctly, therefore i told to use echos to figure out if it actually does return correctly. But i can agree that giving the player a name/global variable can help a lot. Guessing ID is never a good option.
sorry, i just felt that i had to reply, hehe
#4
05/17/2010 (7:17 am)
This could be a case of client id vs server id, they can be different. I would try Steve's idea of adding a name and checking that.
#5
05/17/2010 (8:00 am)
lol, I was not accusing you of "guessing" the ID, Marcus. :)

I often have large numbers of AI in tests and if I forget to use a name, on an echo I end up staring blankly at the four digit return wondering which one of them triggered it.
#6
05/17/2010 (1:13 pm)
Quote:on an echo I end up staring blankly at the four digit return wondering which one of them triggered it
Agree with you there Steve. Your method is indeed the best one to figure who entered the trigger. Maybe i misinterpret the question of this thread, cuz i was explaining at comment #1 how to check if the %obj returns the right value. But i guess we shouldn't keep on discussing on this thread, at least not before Pizzaboy1 answers :D.
#7
05/18/2010 (1:54 am)
Hey, sorry for the late response. Thanks though, I will try both of those first thing in the morning.

I must be doing something wrong. I've tried "echo(%obj);" to no avail. My echo statement always returns an object ID that is +3 of what it should be (it should be the same ID as my player, instead it is 3 greater). I may try echoing %obj.getclassname() to see if it returns the player's class. Is it possible that it is getting the ID of the gun that is mounted to my player? I guess I will find out with more debugging... sorry to bother you guys with this. Thanks again for your responses, those are both viable debugging options.

Sorry if this post doesn't make much sense... I need sleep
#8
05/18/2010 (6:09 am)
Quote:I may try echoing %obj.getClassName() to see if it returns the player's class.
Have you tried this yet? It might just tell us whats wrong.

Quote:Is it possible that it is getting the ID of the gun that is mounted to my player?
I don't think so. Not unless you have changed some original code.
#9
05/18/2010 (6:18 am)
When faced with such things try some - or better - ALL, of the following.

echo("ID= " @ %obj.getID() @ " Name= " @ %obj.getname() @ " Class= " @ %obj.getClassName() @ " State= " @ %obj.getState());

echo("client= " @ LocalClientConnection.getControlObject());

and there's loads more stuff you could do. Until full docs get shipped, try name/player/obj/etc.dump() for a full list of available functions on any object.
#10
05/18/2010 (5:24 pm)
Okay, so I tried the two echo statements you wrote Steve. Here is what they return:

ID = 3973 Name = Class = Player State = Move
Client = 3970

The second echo returns what I had expected it to. I still don't understand why "echo(%obj);" returns an ID that is different than what shows up in the editor ID field for my player. Is that how it's supposed to be? Have I just really misunderstood things?

Referring to Marcus's first post, when my player walks through the trigger it should output an ID in the console, which should match the ID of my player in the editor, right? Is that how it works for you guys?

I can make do with using %obj.getClassName() to make use of my triggers, but I still don't understand this.

Thanks again for your help guys. Sorry for being such a newb
#11
05/18/2010 (6:31 pm)
The editor is showing you the client id, the trigger happens on the server which is showing you the server id. They can be 2 completely different values. You have to keep that in mind in clinet vs server scripting.