Game Development Community

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!

#1
04/13/2013 (10:35 pm)
Great idea pulling the console into its own module - I was thinking of doing that. Unfortunately I'm not sure what might be going on, but I just wanted to mention:
Quote:if I am understanding things correctly, the ModuleId is both the name and class.
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:
GlobalActionMap.bind( keyboard, "ctrl tilde", "SimConsole::ToggleConsole");
I seem to remember binding things to object properties tends to be a bit messy. Also have a look at the bindObj function.
#2
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.