Game Development Community

ConsoleObject vs SimObject

by William Todd Scott · in Torque Game Engine · 11/12/2005 (2:26 pm) · 6 replies

Hey all,

I have created a class which inherits from NetEvent (which inherits from ConsoleObject).

When I try to instantiate my object in script I get a message "Unable to instantiate non-SimObject class".

However, the comments in ConObject indicate:

"That's all you need to do to get a class registered with the console system. At this point,
you can instantiate it via script
, tie methods to it using ConsoleMethod, register fields,
and so forth."



Which is correct? Is there a way to instantiate an object that inherits from NetEvent in script?

Thanks
Todd

#1
11/13/2005 (12:11 pm)
One more thing..if I change my class to inherit from SimObject instead of NetEvent I can instantiate it via script with no problem....but, of course, I need to inherit from NetEvent.

Todd
#2
11/13/2005 (1:50 pm)
You should try to use mutiple inheritence; inherit from SimObject and NetEvent.
#3
11/13/2005 (4:35 pm)
I wasn't sure if that was safe.
Thanks for helping me out.

Edit: Actually, that wont work because both NetEvent and SimObject inherit from ConsoleObject.


Todd
#4
11/13/2005 (9:37 pm)
Sheesh, Josh. :)

No, MI is generally a bad idea unless you know what you're doing.

NetEvents aren't meant to be controlled from script. (If it was SimObject derived then you could send arbitrary NetEvents from script, including internal protocol events, which is a pretty significant security/stability concern.) You can write some simple script wrappers to send NetEvents _for_ script (see the commandToClient/server stuff, this is how that works).

ConsoleObject implements the core instantiation logic, first thing the script engine does once its made an object by classname is do a dynamic_cast to make sure it's a SimObject - if not, then it can't do anything with it, since it does things like refer to objects by ID and assume that it can do safe references.
#5
11/14/2005 (7:05 am)
Ok, thanks Ben.
#6
11/18/2005 (11:15 am)
As Ben mentions, NetEvents aren't meant to be treated as game world objects, and therefore aren't instantiated from script directly.

However, they can be triggered for creation/processing from script, depending on what you actually wish to do with them...for example, the commandToClient/commandToServer functionality does exactly that--creates a NetEvent that is then handled on the "other" side of your client-server model.