ScriptThis() versus object ID
by Daniel Buckmaster · in Torque Game Engine · 09/01/2007 (1:39 pm) · 5 replies
I've noticed that when you call a script function from code, using scriptThis() as an argument, the number passed to the script function is different to the object's ID number as seen in the editor.
How can I fix this so that the number seen in the editor is passed to script functions?
How can I fix this so that the number seen in the editor is passed to script functions?
About the author
Studying mechatronic engineering and computer science at the University of Sydney. Game development is probably my most time-consuming hobby!
#2
09/01/2007 (10:09 pm)
Okay, thanks. So basically, how can I get scriptThis() to return server IDs? Do I have to do something to the client ID after I get it? Or do I have to usesomething other than scriptThis()?
#3
I'm still not sure I fully understand your question though. What exactly is scriptThis()?
09/01/2007 (11:08 pm)
I'm still wrapping my head around this area of Torque however I believe you might want to take a look at the getGhostID() function.I'm still not sure I fully understand your question though. What exactly is scriptThis()?
#4
ScriptThis() is just a convenience function around doing a Con::getReturnBuffer() and sPrinting the object's ID into it:
so if you're seeing a discrepancy between scriptThis() and the ID you're expecting,
it's likely because in one case you're dealing with a server-side object and in the other a client-side one.
Objects are instanciated on both the server and each client, even if you're running in single-executable, single-player mode, and the server instance and each client instance of the 'same' object will have different simIDs. This is definitely the most confusing thing to grasp in TGE networking, but there are many posts in the forums and hopefully in TDN describing it. Tim is also correct that the key to correlating server and client simIDs for the 'same' object is the getGhostID() family of functions.
09/02/2007 (12:02 am)
Daniel - i think Tim has the right suggestion here.ScriptThis() is just a convenience function around doing a Con::getReturnBuffer() and sPrinting the object's ID into it:
const char* SceneObject::scriptThis()
{
return Con::getIntArg(getId());
}
...
char *getIntArg(S32 arg)
{
char *ret = STR.getArgBuffer(32);
dSprintf(ret, 32, "%d", arg);
return ret;
}so if you're seeing a discrepancy between scriptThis() and the ID you're expecting,
it's likely because in one case you're dealing with a server-side object and in the other a client-side one.
Objects are instanciated on both the server and each client, even if you're running in single-executable, single-player mode, and the server instance and each client instance of the 'same' object will have different simIDs. This is definitely the most confusing thing to grasp in TGE networking, but there are many posts in the forums and hopefully in TDN describing it. Tim is also correct that the key to correlating server and client simIDs for the 'same' object is the getGhostID() family of functions.
#5
EDIT: In addition, can this be done without using a server command? Every implementation of this sort of stuff I've seen uses a server command to do something, and only calls the server command from the client. I have a somewhat different setup, I think:
-GUI element executes script callback, passing a server ID
-Function in client script calls function on LocalClientConnection's player's datablock
-When a key is pressed, client function (in default.bind) executes functions on the Player datablock depending on the Player object's member fields
09/02/2007 (12:13 am)
Okay, thanks everyone for the info! I did a little research, which got me to the point of understanding tht things have different IDs on server and client. However, looking for the documentation of things like getGhostID and resolveObjectFromGhostIndex didn't return very much (broken links in TDN, web filter blocking... grr...).EDIT: In addition, can this be done without using a server command? Every implementation of this sort of stuff I've seen uses a server command to do something, and only calls the server command from the client. I have a somewhat different setup, I think:
-GUI element executes script callback, passing a server ID
-Function in client script calls function on LocalClientConnection's player's datablock
-When a key is pressed, client function (in default.bind) executes functions on the Player datablock depending on the Player object's member fields
Torque Owner Tim Heldna
So long story short, this may explain why you're seeing different ID's.