Client Side onAdd
by Timothy C. Pelham · in Torque Game Engine · 05/22/2007 (5:15 pm) · 3 replies
I have an object (StaticShape) that has an onAdd function, but the function is working properly on the server and not being called on the client.
There are a couple of oddities I'm experiencing. Number one is custom data put into a datablock does not appear to be working correctly.
If I do the following:
datablock StaticShapeData(example)
{
category = "Misc";
shapeFile = "client/data/shapes/example.dts";
isOpen = false;
someData = 1;
};
When I call echo([theobjectsID].someData); it appears empty on both the client and the server. To over-ride this I had manually added the data into the onAdd function of the object.
function example::onAdd(%db, %obj)
{
%obj.someData = 1;
}
Now if I attempt to get the information it shows up correctly on the server, but not the client. Only the server object is setting the someData field to 1.
I'm not sure why this is happening, but it seems like a fairly obvious over-sight on my part.
Thanks for any help.
There are a couple of oddities I'm experiencing. Number one is custom data put into a datablock does not appear to be working correctly.
If I do the following:
datablock StaticShapeData(example)
{
category = "Misc";
shapeFile = "client/data/shapes/example.dts";
isOpen = false;
someData = 1;
};
When I call echo([theobjectsID].someData); it appears empty on both the client and the server. To over-ride this I had manually added the data into the onAdd function of the object.
function example::onAdd(%db, %obj)
{
%obj.someData = 1;
}
Now if I attempt to get the information it shows up correctly on the server, but not the client. Only the server object is setting the someData field to 1.
I'm not sure why this is happening, but it seems like a fairly obvious over-sight on my part.
Thanks for any help.
About the author
#2
Except for client only objects, like a GUI control, or functions that operate with a client only object, script functions should only be executed on the server. There are exceptions.
05/23/2007 (10:39 am)
OnAdd calls are prevented on the client because the server would typically be in control of whatever you wanted to do in there anyway.Except for client only objects, like a GUI control, or functions that operate with a client only object, script functions should only be executed on the server. There are exceptions.
#3
The problem arose, naturally, when I needed this information on the client to propagate the menu properly. From your responses I'm thinking creating a separate interactive object would be beneficial. An object that is a child of StaticShape and has the variables I'm looking for (as well as anything else I would need for it). That way I can use the pack/unpack to transfer the information from the datablock to the client.
Does this seem like a logical way to handle the issue?
Thanks for all the help.
05/23/2007 (1:22 pm)
Thanks for the responses. I have a better idea of what's going on now. I'm attempting to create an interactive object. This is for a multiplayer game and the object can have various ways of interacting. I was using a canExamine/canUse/canInteract variables that are used to determine what is displayed in a pop-over menu when you right click an object on the screen.The problem arose, naturally, when I needed this information on the client to propagate the menu properly. From your responses I'm thinking creating a separate interactive object would be beneficial. An object that is a child of StaticShape and has the variables I'm looking for (as well as anything else I would need for it). That way I can use the pack/unpack to transfer the information from the datablock to the client.
Does this seem like a logical way to handle the issue?
Thanks for all the help.
Associate Orion Elenzil
Real Life Plus
so %serverSideObject.getDatablock().someData should be correct.
also custom fields you add to the DB via script are not communicated to the client.
if you want to do that you'll need to add them to the datablock's packData() function in the engine.
re onAdd(),
a couple things -
1. it ain't called client-side. i'm not sure why this is. in GameBase::scriptOnAdd() it's explicitely prevented on the client. i went ahead and changed this for certain objects like players.
2. even server-side, not all objects do an onAdd() callback. again, not sure why this is. GameBase objects do.