Question about Modules
by Dylan Taft · in Torque 2D Beginner · 04/13/2013 (9:55 pm) · 2 replies
Ah - how do I keep this simple
In the old Torque2D, you could name and define a function
Whatever::doSomething(%this)
Whatever is the "namespace"
Then you can create a new named instance
%someobj = new SimObject(NamedObject)
{
class = Whatever;
}
NamedObject.doSomething() would work as expected.
OK!
Now, Modules, in the new Torque
You have to set CreateFunction and DestroyFunction in your module's taml file.
Say you do CreateFunction = "create"
Then, you define the function as
ModuleName::create()
Ok, easy so far.
So, a Module is a named SimSet, if I am understanding things correctly, the ModuleId is both the name and class.
I guess, bottom line is,
in my module's create function, the module's ID is SimConsole
GlobalActionMap.bind( keyboard, "ctrl tilde", SimConsole.ToggleConsole);
SimConsole::ToggleConsole never get's called when I hit ctrl-tilde. No error, just nothing. If I manually call SimConsole.ToggleConsole(), it works fine.
If I remove the namespace from SimConsole::ToggleConsole(% make) it works fine .
So, somewhere, I'm slightly not understanding something.
Edit: Basically, I ripped out the "Console" functions and GUI from the Sandbox demo, simplified it, and put it in it's own module called SimConsole that I can easily load into other projects. It works 100% correctly when I have ToggleConsole outside of a namespace.
Modules are really slick and powerful!
In the old Torque2D, you could name and define a function
Whatever::doSomething(%this)
Whatever is the "namespace"
Then you can create a new named instance
%someobj = new SimObject(NamedObject)
{
class = Whatever;
}
NamedObject.doSomething() would work as expected.
OK!
Now, Modules, in the new Torque
You have to set CreateFunction and DestroyFunction in your module's taml file.
Say you do CreateFunction = "create"
Then, you define the function as
ModuleName::create()
Ok, easy so far.
So, a Module is a named SimSet, if I am understanding things correctly, the ModuleId is both the name and class.
I guess, bottom line is,
in my module's create function, the module's ID is SimConsole
GlobalActionMap.bind( keyboard, "ctrl tilde", SimConsole.ToggleConsole);
SimConsole::ToggleConsole never get's called when I hit ctrl-tilde. No error, just nothing. If I manually call SimConsole.ToggleConsole(), it works fine.
If I remove the namespace from SimConsole::ToggleConsole(% make) it works fine .
So, somewhere, I'm slightly not understanding something.
Edit: Basically, I ripped out the "Console" functions and GUI from the Sandbox demo, simplified it, and put it in it's own module called SimConsole that I can easily load into other projects. It works 100% correctly when I have ToggleConsole outside of a namespace.
Modules are really slick and powerful!
#2
"SimConsole::ToggleConsole" with bind did not work.
04/14/2013 (12:49 am)
Neat, bindObj works, if I put %this as the object! That's exactly what I want, thank you!"SimConsole::ToggleConsole" with bind did not work.
Torque Owner Daniel Buckmaster
T3D Steering Committee
In TorqueScript, an object's name is in its class hierarchy. Observe:
new SceneObject(ObjectName) { class="MyClass"; }; function MyClass::hello { echo("hello"); } ObjectName.hello(); // Prints "hello"But:new SceneObject(ObjectName) { class="MyClass"; }; function MyClass::hello { echo("hello"); } function ObjectName::hello { echo("I win"); } ObjectName.hello(); // Prints "I win"In effect, the object's name is another 'class' above the actual 'class' the object is designated as.
What happens if your call to bind looks like this:
I seem to remember binding things to object properties tends to be a bit messy. Also have a look at the bindObj function.