How Do I Call a Module's Methods Based on ModuleId
by practicing01 · in Torque 2D Beginner · 02/24/2013 (11:15 pm) · 3 replies
Is it even possible? Say I load a module with ModuleId="beach". In a script file I have: "function beach::loadlevel()...". I could call the function with "beach.loadlevel();". What I have though, is what ModuleDatabase.findModule() returns. How do I use that to call loadlevel()?
#2
02/24/2013 (11:58 pm)
Yes! That worked beautifully, thanks Melv. For anyone interested, toolbox.cs uses it @ line 286. Very useful function.
#3
I'll probably be writing the module manager guide this week so that should help as well.
02/25/2013 (12:01 am)
No problem.I'll probably be writing the module manager guide this week so that should help as well.
Associate Melv May
This object is a SimSet that is created when the module is loaded and is destroyed (along with anything that's added to it) when the module is unloaded.
If one module is calling into another, you should ensure that the module you're calling into is loaded prior to calling into it from another module. You can do this by adding in a module dependency from the module you're calling from to the module you're calling into like this:
<ModuleDefinition ModuleId="SomeModule" Dependencies="Beach=1" ...This kind of dependency is being used in the Sandbox to ensure that the "ToyAssets" module is loaded prior to certain modules like here. You use multiple modules using a "comma" as a separator.
If however you are interested in "findModule()" then it returns you the module definition. Think of it as the equivalent of finding an asset object from an asset Id. In this case you can find the module object using a module Id (and version Id).
If you look at a module definition file (probably "module.taml") you'll see the object that you defined, it's the object in the example above. This is what you can retrieve using "findModule()" (and others) and it always exists even before a module is loaded.
If you look at the source for Module Definition (approx line 105) then you'll see a field named "ScopeSet". This is the named object i.e. you can do something like:
... but obviously using that objects name like so:
... is easier, it depends on what you're doing.
To hit this home, here's how to output a modules description as entered into its module definition:
echo( ModuleDatabase.findModule("Beach", 1).Description );