Can't get shapebase derived class accessible in scipt
by Drew Parker · in Torque Game Engine · 05/07/2004 (11:40 am) · 6 replies
I've been trying to get a ShapeBase derived object accessible in script (as a member object), but it won't work. My object is a member of the Player class. When I try to access it, I always get a null pointer. I've done all the initPersistFields stuff in the Player class, and tried many different avenues to get it working, but can't seem to cut it. I've also done a %player.dump() from script, and you can see the new object, it's just always null, even after I've initialized from C++ code.
My guess is the variable is not being passed correctly from engine to script and vice-versa. Because in initPersistFields, you have to declare a type with your member field, like so:
so the engine knows how to treat the object. However, I'm trying to make a member field that is a complex Torque object. Seems like this should be possible somehow? The only type I could find that I thought fit the bill was TypeSimObjectPtr, which I found in consoleTypes.h. But TypeSimObjectPtr iss not accessed anywhere in the engine, so I'm wondering if it's fully functional. All the other types defined are datablock types or regular types like bool, vector, etc...
Here's what I want to do from script:
Next stop is creating my own type and making the get/set functions as recommended in the docs in the section Adding Class Member Fields. I actually tried this already too, but couldn't get it to work, guess I'll try again. I called Con::registerType() on it and everything, but it still didn't seem to work right, and I was getting flaky results.
Am I going about this the totally wrong way and making this hard on myself? Is this functionality built in somewhere and I've just missed it?
My guess is the variable is not being passed correctly from engine to script and vice-versa. Because in initPersistFields, you have to declare a type with your member field, like so:
addField("hudImageNameEnemy", [b]TypeString[/b] ,
Offset(hudImageNameEnemy, ShapeBaseData), NumHudRenderImages);
addField("hudRenderCenter", [b]TypeBool[/b] ,
Offset(hudRenderCenter, ShapeBaseData), NumHudRenderImages);so the engine knows how to treat the object. However, I'm trying to make a member field that is a complex Torque object. Seems like this should be possible somehow? The only type I could find that I thought fit the bill was TypeSimObjectPtr, which I found in consoleTypes.h. But TypeSimObjectPtr iss not accessed anywhere in the engine, so I'm wondering if it's fully functional. All the other types defined are datablock types or regular types like bool, vector, etc...
Here's what I want to do from script:
%player.myShapeBaseObject.doSomething(); [i]or[/i] %player.myShapeBaseObject.setDataBlock (myDatablock);
Next stop is creating my own type and making the get/set functions as recommended in the docs in the section Adding Class Member Fields. I actually tried this already too, but couldn't get it to work, guess I'll try again. I called Con::registerType() on it and everything, but it still didn't seem to work right, and I was getting flaky results.
Am I going about this the totally wrong way and making this hard on myself? Is this functionality built in somewhere and I've just missed it?
About the author
#2
05/07/2004 (6:31 pm)
Excellent work. You solved your own problem very nicely - I could not have solved it better myself. :)
#3
05/11/2004 (7:26 am)
Thanks Ben. Sometimes it seems I work a long time on a problem, finally decide it's hopeless and I better post on the forums, only to realize one hour later it was an easy solution I missed. :) But you just do your best at the time, I suppose.
#4
I am sure I am about to run into this very problem as I am working on a new object class definition and I dont fully understand how the engine can tell when an object is on the server vsus the client.
The object is actually an in game object, so its going to be scoped sometimes to the client. But other times its only going reside as a reference inside of a player's inventory. (Im doing an object based inventory system.) Which may or may not get scoped to the client. (Dont know how this will work yet.)
Just curios on what kind of code you were writing that helped to only run it if it as on the server. (I'm having trouble picturing code that runs differntly based on its location across a network.)
Hope your still around, I could use some enlightening. :D
06/17/2004 (4:17 pm)
If you dont mind, can you elaborate a little more on how to use isServerObject() effectively?I am sure I am about to run into this very problem as I am working on a new object class definition and I dont fully understand how the engine can tell when an object is on the server vsus the client.
The object is actually an in game object, so its going to be scoped sometimes to the client. But other times its only going reside as a reference inside of a player's inventory. (Im doing an object based inventory system.) Which may or may not get scoped to the client. (Dont know how this will work yet.)
Just curios on what kind of code you were writing that helped to only run it if it as on the server. (I'm having trouble picturing code that runs differntly based on its location across a network.)
Hope your still around, I could use some enlightening. :D
#5
I had the "notify me" marker checked by chance, so it turns out I am still around. :)
The isServerObject() command is used to specify where a chunk of code should run, on the client or on the server. I haven't had to use it that often, but it can come in handy. Most of the time having code run the same on client and server is fine.
You can see lots of good examples in the code. Some are in processTick() for various ShapeBase objects, like Item and Player. Just do a search for isServerObject() and that should bring them up. One thing off the top of my head, lets say you want to play an animation... you don't want that running on the server right? Only client's need to play animations. So maybe you would write:
Hope that helps... Sorry I can't give more in-depth details or examples, I've only had to use it once actually, so I don't have the best grasp on all the different situations it can or should be used in.
06/17/2004 (6:23 pm)
Hi David,I had the "notify me" marker checked by chance, so it turns out I am still around. :)
The isServerObject() command is used to specify where a chunk of code should run, on the client or on the server. I haven't had to use it that often, but it can come in handy. Most of the time having code run the same on client and server is fine.
You can see lots of good examples in the code. Some are in processTick() for various ShapeBase objects, like Item and Player. Just do a search for isServerObject() and that should bring them up. One thing off the top of my head, lets say you want to play an animation... you don't want that running on the server right? Only client's need to play animations. So maybe you would write:
// if we are not the server...
if (!isServerObject())
{
[i]...run some animation code...[/i]
}Hope that helps... Sorry I can't give more in-depth details or examples, I've only had to use it once actually, so I don't have the best grasp on all the different situations it can or should be used in.
#6
Ohh and just for the sake of hilarity. Wanna know something freaky?
When I posted I thought.. "Hmm, I wonder if their notify me is checked?"
:D
Thats part of why I leave mine on. Never know when something interesting might happen to something I used to care about. :D
06/17/2004 (8:22 pm)
Ok, thanks. Ill dig into it some more.Ohh and just for the sake of hilarity. Wanna know something freaky?
When I posted I thought.. "Hmm, I wonder if their notify me is checked?"
:D
Thats part of why I leave mine on. Never know when something interesting might happen to something I used to care about. :D
Torque 3D Owner Drew Parker
It turns out that TypeSimObjectPtr works fine. I kept getting null pointer errors in script, so it seemed like the types weren't passing correctly. And the behaviour was real unpredictable when debugging.
What was ACTUALLY happening was the debugger was hitting the client *and* server versions of the player object in different orders, and my ShapeBase object was only created server-side, so it was showing up as null.
To resolve the problem I used the isServerObject() command like so
to seperate my C++ code chunks between client and server.