Is ConsoleStaticMethod what I am looking for?
by Michael Woerister · in Torque Game Builder · 03/16/2006 (10:13 am) · 3 replies
Is the ConsoleStaticMethod() macro the same as ConsoleFunction() with the exception that the created function will be put in the namespace specified by "className"?
That would be handy.
-Michael
That would be handy.
-Michael
#2
EDIT: I didn't realize there was a ConsoleStaticMethod macro.
03/16/2006 (12:07 pm)
ConsoleMethod is the actual macro. And yes, it will make that method available to script when called on an object of that particular className. However, the class you are doing this on must have done the appropriate setup work first, ie: the DECLARE_CONOBJECT / IMPLEMENT_CONOBJECT macros.EDIT: I didn't realize there was a ConsoleStaticMethod macro.
#3
The same here. Found it when I was looking for something like the above.
03/16/2006 (12:24 pm)
Quote:
I didn't realize there was a ConsoleStaticMethod macro.
The same here. Found it when I was looking for something like the above.
Torque Owner Michael Woerister
#define ConsoleNamespaceMethod(className,nameSpace,name,returnType,minArgs,maxArgs,usage1) \ static inline returnType c##nameSpace##name(className *, S32, const char **argv); \ static returnType c##nameSpace##name##caster(SimObject *object, S32 argc, const char **argv) { \ AssertFatal( dynamic_cast<className*>( object ), "Object passed to " #name " is not a " #className "!" ); \ conmethod_return_##returnType ) c##nameSpace##name(static_cast<className*>(object),argc,argv); \ }; \ static ConsoleConstructor nameSpace##name##obj(#nameSpace,#name,c##nameSpace##name##caster,usage1,minArgs,maxArgs); \ static inline returnType c##nameSpace##name(className *object, S32 argc, const char **argv)This macro works exactly like ConsoleMethod but puts the resulting method in the namespace specified with nameSpace. Combine this with cool functionality from this and you can implement any method you want in c++ and use it as before.
Example:
// C++ implementation ConsoleNamespaceMethod(t2dSceneObject,Player,doSomething,void,2,2,"Player::doSomething()") { object->setPosition( object->getPosition() ); } // usage in Torque Script $player = new t2dSceneObject() { class = "Player"; }; $player.doSomething();Nothing big but handy - especially when you need to optimize but cannot implement the whole object in C++ because then you can't create and modify it in the level editor anymore.