Game Development Community

How Do I Get An Object ID ?

by Michael Hense · in Torque Game Engine · 06/22/2005 (7:22 pm) · 8 replies

I have an object instantiated on the server, and have succeeded in getting the clients to see it when they connect...

but i have no idea how to get an ID for this, or any ghosted object on the client...

any help along these lines... or pointing me in the right direction would be greatly appreciated...

i'm trying to do all this in script...

thx in advance

--Mike

#1
06/22/2005 (7:52 pm)
Just by doing an "echo" call in the console you can get the id of any object in your game. For instance, when you start a server you recieve a client id. When your player character spawns your client reieves a player id.

Pasted from my console.log file
Executing base/data/missions/test1.mis.
*** Mission loaded
Connect request from: IPX:CECECECE:CECECECECECE:52942
Connection established 1249
[i]CADD: 1250 local[/i]

As you can see, my client ID is 1250. Now that im in game and my player is running around I can drop the console and use "echo(1250.player);" and that will return the ID for the player.
#2
06/22/2005 (9:33 pm)
I'm not sure what you are trying to do, but you can use .getID(); usually to return the ID assigned to the object when it was created.

There are many ways to work towards the ID as Sam pointed out one way above.

Using the console to work out the ID you need with echos is probably the easiest way to figure it out.

And the object will also have an ID in the mission editor, so you can figure out what number you are trying to come up with if you select your item and look it up in the mission editor.



Without knowing how your object is created and how you are trying to use it, That is about as much as I can point right now.
#3
06/23/2005 (1:25 am)
The RTS Starter Kit has some excellent examples of working with objects, their ids, their ghosts, and the ids of those ghosts... How to do things like transmit a reference to an object over the net connection.
#4
06/23/2005 (6:38 am)
Thanks guys... what i'm trying to do is get a working understanding of the communications between the server and client...

i think i understand the basic concept behind creating objects on the server and having them ghosted on the client... but what i fail to grasp is how to identify a ghosted object on the client (ingame) to the server, so that i can manipulate the object (ie, move it)...

for example... i have the little cylindrical flying capsule that players can get inside of, and then by pressing a control key cause it to move up and move forward... but i can't figure out how to identify the object to the server so that i can move it on the server... and have it move on all the clients as well...

this is the code i used to create the capsule on the server... verrry simple, no security concerns as of yet... the function insertTestShip() is called from server.cs onMissionLoaded handler...


// testship.cs

datablock ItemData(TestShip){
  shapeFile="control/data/shapes/TestShip/Hull2.dts";
  mass=1;
  friction=1;
};
  

function InsertTestShip(){
    $TestShip=new Item(){
    rotation="0 0 1 0";
    position = "-45.8946 -21.6984 201.921";
    scale="1 1 1";
    dataBlock= "TestShip";
    };
  MissionCleanup.add($TestShip);
   $TestShip.setTransform( "-45.8946 -21.6984 201.921");
   //return %TestShip;
   //commandToClient(%client,'ShowTestShip');
}

my first server object (i was so happy to see it appear... and then on another client as well :) )...

just a second... just a second...

... while writing this something just occurred to me... i may be confused about this and trying to do something i really don't need to do...

i already know the object name on the server, a straight forward commandToServer() might work...

be right back...


--Mike
#5
06/23/2005 (7:19 am)
Ok... i set up a commandToServer function and a corresponding serverCmd function handler... but nothing is happening...

the console shows the cmd mapping of the tagged string, but that's it... no error messages, no movement...

it seems like i still need to know how to identify the object on the client end... a ghostedIndex or sometehing maybe...

i've seen some code that accepts %client.getCurrentMountedVehicle() on the server... is there a way to just get a ghosted objects id in the game???

disregard all above... i am such a brick... brick, brick, brick

it was just a matter of grasping the concept, and not over thinking it in an attempt to implement some simple functionality...

the solution was simple... although i couldn't see it immediately :)

seeing as the object is created on the server... all i needed was to just have the client send a command to the server, and move it there... no need to pass an object id seeing as the object will always be the same in this case...

home.att.net/~mikey102/TGE3Some.jpg
a scene from Ken's book... slightly modded with a cylindrical style 'ship' propogated to all clients from the server, and 3 clients (players)... 2 windows and a macintosh client... each able to move the 'ship'...

THANKS people for helping me out on this... and for your patience...

--Mike
#6
06/23/2005 (10:54 am)
Glad you got it working. Best way to solve a problem is often to avoid it entirely! :)
#7
06/27/2005 (6:28 am)
Just for those following up on this thread in the future:

While his technique worked, it's not particularly generic, so I thought I'd discuss the topic just a bit:

When an object is created on the server (the only place any object that more than one client will need to see should be created), it is assigned a server side Object ID. THIS is the only ID the server should ever use for manipulation of the object.

Now, when that object is set to be ghostable, and is scoped to a particular client, during the process of scoping that object to each client, the server tells each client to reference the object via a client-specific ghost ID. Note that a couple of facts exist here:

1) The clients NEVER know what the object's server ID is...only what the ghost ID the server told them to use is.
2) EACH client gets their own unique ghost ID for that server object, so you cannot pass ghost ID's directly from a client to another client.
3) The server keeps track of which ghost ID was assigned to which client for each server object that is ghosted.

As Ben mentioned, there are several examples in in the RTS SK demonstrating how to use ghost ID's back and forth between a client and the server. In general, the client sends the server it's assigned ghost ID, and the server uses built in console methods in the client object (ClientConnection) to resolve these ghost ID's into server ID's. An example is the script method resolveObjectFromGhostIndex(%ghostID);
#8
06/29/2005 (5:02 am)
Thanks for the additional insights Stephen...

--Mike