Game Development Community

Resolved - Getting serverside ObjID from the client side ID

by Flybynight Studios · in Torque Game Engine · 07/20/2007 (8:38 am) · 3 replies

Seems to be a few posts on this but nothing I've tried works..

Is there a way to do this without modifying the source? Seems to be C++ code in the engine already to do this I just cant seem to find the Torque script to do it.

Right now I have the client passing a ghostID to the server that they want information about. I want the server to pass some info about the object back to the client but not all the info. I'll pass it back in a commandtoclient.

Thanks

#1
07/20/2007 (9:49 am)
This link tells the right way to do it:
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=4852
Sure, you have to add the ConsoleFunctions somewhere in C++ code, but it's really easy to do and you can put them just about anywhere.
#2
07/20/2007 (10:03 am)
I started to punch out some code for you, but then I realized that I wasn't entirely sure I knew what I was doing and I don't have any convenient way to test it quickly. So instead, I'll point you at what I was about to do...

If I understand correctly, the magic word you're looking for is "%client.resolveObjectFromGhostIndex(%ghost);"
I'm not entirely sure of the syntax of this and whether or not you'd have to first use "%ghost = %client.getGhostID(%selection)," but I'm sure you can tinker with it and figure it out. The best method I found for understanding this stuff is to write a quick serverCmd that echoes all the IDs you're playing with to the console, and then invoke it from the client console to see if you can figure some of this stuff out.

Here's the TDN page that I used as referance:
tdn.garagegames.com/wiki/Torque/Networking/Ghosting
and this example looked like it might be pertinent to you:
tdn.garagegames.com/wiki/Torque/Networking/Ghosting/Examples
#3
07/20/2007 (11:40 am)
Thanks so much guys. I did a little soul searching on this this morning and thanks to some digging and help from the IRC crew I came up with this..

Instead of passing the obj from the client as simply %this.. You use %this.getghostID()

Example:
function ShapeBase::onSelect(%this)
{
	error("Selected item" @ %this ); 
	commandToServer('NotifyServerSelect',%this.getghostID());
}

Then on the server you resolve the ghostID to the serverobjID using.. %client.resolveobjectfromghostindex(%val);

Example:
%targetid = %client.resolveobjectfromghostindex(%val);
	%targetname = %targetid.dataBlock.pickupname;

Thank you again for pointing me at the right resources. Good luck on your work.