Game Development Community

Server commands and IDs

by Daniel Buckmaster · in Torque Game Engine · 09/10/2007 (11:04 am) · 5 replies

I'm trying to use a server command to get the server ID of an object based on its client-side ID. Should be simple, right?
function serverCmdGetServerID(%client,%object)
{
   echo(%client.resolveObjectFromGhostIndex(%object));
}
This echoes 0, even when passed values I know should work. I got the value from a client-side function called by the GUI (something like the Advanced Crosshair resource), but this value differs from the value I see in the world editor - supposedly, this value is the server ID. Right? If I add a .getGhostID, the function returns an ID, but, for example, calling mountObject using the returned ID has no effect (whereas, mountObject using the ID seen in the editor works).

Basically, I want to know how to use scripts (client commands, server commands, whatever) to get the ID of an object as displayed in the editor.

About the author

Studying mechatronic engineering and computer science at the University of Sydney. Game development is probably my most time-consuming hobby!


#1
09/10/2007 (12:12 pm)
%client in your server function will return GameConnection.
#3
09/12/2007 (12:22 pm)
Say you have a vehicle object ghosted from the server, whose local client object ID is %localObj. (Not trivial to get for some things, perhaps)

on the client side you would:
%thisClientGhostId = %localObj.getGhostID();
commandToServer('GetServerID',%thisClientGhostId);

The server then uses resolveObjectFromGhostIndex as you have programmed to resolve that client's version of the ghostID to the servers objectID.

I have tested exactly this method recently and it worked fine.

Problems might come in from not understanding that the localObj id is not the same as the ghostID, or somehow the %localObj wasn't correct.

In my case, the client's id for the ghosted car is 1863, and the ghostID = 2, finally the server car obj id = 2067


This probably doesn't answer your question here however:
Quote:Basically, I want to know how to use scripts (client commands, server commands, whatever) to get the ID of an object as displayed in the editor.
(I'm afraid I don't really have a good idea of what is going on in the editor, so can't help there.)

But perhaps it points toward a problem or misconception that might be hindering things.



----

Rereading your post, from what you report it sounds like the editor works in server side IDs. (Which makes some sense)

It seems like the problem would be in getting the proper %localObj for your player on the client, to start things off.

Take a look at how GuiHealthBarHud.cc gets a pointer to the local control object (a Player). If you do a ptr->getId() you will get the ID that I've been calling %localObj (method via the shapebase base class, IIRC).

What the gui element is actually talking to is the "Ghost Object". This is the client side object that tracks the servers object via packet updates from the server. Luckily, the server is updating the ghost with enough health data to make that useful. (In general, not all the members of the ghost object will have valid data, just whatever is specifically programmed to be sent over from the server or derived locally.)

How to get these local client object ID's otherwise I haven't played with. You might try the various "pick an object with the cursor" type resources since it seems that is what they would be working with.
#4
09/13/2007 (10:32 am)
Thanks a lot! I'll have a go again...
Quote:You might try the various "pick an object with the cursor" type resources since it seems that is what they would be working with.
Yeah, I really should have gone there first :P. I did look the context sensitive crosshair resource, but it's not extremely clear about the client/server side of things. Meh. I'll have another go...

Okay, here are the scripts:
In the client/scripts/playGui
function GuiCrossHairHud::onObjectSelected(%this,%obj)
{
   echo("object ID:" SPC %obj);
   echo("ghost ID:" SPC %obj.getGhostID());
   commandToServer('getServerID',%obj.getGhostID);
}
(That callback returns the scriptThis() ID of the selected object... maybe that's the problem?)

In server/scripts/commands
function serverCmdGetServerID(%client,%object)
{
   echo("server ID:" SPC %client.resolveObjectFromGhostIndex(%object));
}

That says I have an object ID of 1556, ghost ID of 3, and server ID of 1550. The number shown in the editor is 1535. Doing a mountObject using 1550 does nothing, but there's no error; using 1556 has wierd results (the object doesn't move but it gets rendered in odd positions); using 1535 works perfectly. That's why I want 1535 :P...
#5
07/08/2012 (12:24 am)
this might be late but this worked for me in the above code to send the CMD to server you have %obj.getGhostID instead of %obj.getGhostID()