Difference between revisions of "MPUZ: Plugins"

From Mario Fan Games Galaxy Wiki
m (MPUZ: Modules moved to MPUZ: Plugins: no longer called modules... duh)
m
Line 1: Line 1:
 
{{MPUZ}}
 
{{MPUZ}}
'''Modules''' are special precoded functions that can be added to object code to make the object inherit some sort of behavior. For example, an '''[[MPUZ: Objects|MP_Shell]]''' object contains '''mod.hasmovement()''' and '''mod.frictionless()''' modules. The former gives the object gravity, slope support, and basic background collisions, while the latter keeps the object from decelerating on slopes... or any surface for that matter. Some modules can take parameters, which allows various default values to be changed.
+
'''Plugins''' are special precoded behaviors useful for quickly giving multiple objects commonly-used functionality. For example, the plugin called "moves" would add gravity and basic background collision detection to an instance. For the most part, plugins are assigned to objects within the [[MPUZ: Object Editor|Object Editor]], and usually don't need to be touched during the game.
  
When a module is activated, it makes an entry in its object's ''mod'' table. For example, '''mod.hasmovement()''' will set ''me.mod.hasmovement'' to '''true''', activating the module and initializing any variables that it uses. Some modules may automatically activate other modules.
+
Plugins can be attached to and removed from object instances, or can be temporarily disabled and later re-enabled. Found in the ''plugin'' table for instances, it is easy to see which plugins are present. Their state is also available, as either "active" or "inactive". For example, this information would be stored internally like:
 +
 
 +
<nowiki>instance = {
 +
    ...
 +
    plugin = {
 +
        ["moves"] = "active",
 +
        ["wraps"] = "inactive",
 +
        ["pickup"] = nil, -- either deinitialized or never actually attached
 +
    },
 +
    ...
 +
}</nowiki>
 +
 
 +
==Events==
 +
Plugins use a similar events system as objects, though it is much reduced as they do not need nearly as many events as objects:
 +
'''Triggered'''
 +
*'''onInitialize()''': essentially the area where variables will be initialized; this is called one time when the plugin is attached to an object instance.
 +
*'''onDeinitialize()''': called once when the plugin is detached from an instance (or, by extension, if that instance is destroyed beforehand). Any cleanup of variables should be carried out in this event.
 +
*'''onActivate()''': called once each time the plugin is activated.
 +
*'''onDeactivate()''': called once each time the plugin is deactivated.
 +
'''Continuous'''
 +
*'''main()''': where most of the plugin's code will usually go; effectively the behavior itself.
 +
 
 +
==API functions==
 +
*'''[[MPUZ: Generic Terms|selector]]:attachPlugin( ''STRING'' plugin_name )''': attaches plugin then calls ''onInitialize()''
 +
*'''selector:detachPlugin( ''STRING'' plugin_name )''': calls ''onDeinitialize()'' then detaches plugin
 +
*'''selector:activatePlugin( ''STRING'' plugin_name )''': calls ''onActivate()'' and resumes execution of plugin
 +
*'''selector:deactivatePlugin( ''STRING'' plugin_name )''': calls ''onDeactivate()'' and suspends execution of plugin
  
 
== Module list ==
 
== Module list ==
*'''mod.frictionless()''': Object will never decelerate, and will keep moving until its motion is stopped another way.
+
''(unfinished)''
*'''mod.hasmovement()''': Object is affected by gravity, and has background collision and slope support. However, it does not make the object controllable by the player.
+
*'''plugin.moves()''': Object is affected by gravity, and has background collision and slope support. However, it does not make the object controllable by the player.
*'''mod.wrap()''': Object will wrap around the level boundaries should it leave them.
+
*'''plugin.wraps()''': Object will wrap around the level boundaries should it leave them.
 +
*'''plugin.pickup()''': Object can be picked up and carried by the player

Revision as of 00:52, 15 May 2009

This information is subject to change.
MPUZ
Mpuz logo.png
Development Main Page
Basics
Intermediate
Advanced
  • none
Reference
[Edit]


Plugins are special precoded behaviors useful for quickly giving multiple objects commonly-used functionality. For example, the plugin called "moves" would add gravity and basic background collision detection to an instance. For the most part, plugins are assigned to objects within the Object Editor, and usually don't need to be touched during the game.

Plugins can be attached to and removed from object instances, or can be temporarily disabled and later re-enabled. Found in the plugin table for instances, it is easy to see which plugins are present. Their state is also available, as either "active" or "inactive". For example, this information would be stored internally like:

instance = {
    ...
    plugin = {
        ["moves"] = "active",
        ["wraps"] = "inactive",
        ["pickup"] = nil, -- either deinitialized or never actually attached
    },
    ...
}

Events

Plugins use a similar events system as objects, though it is much reduced as they do not need nearly as many events as objects: Triggered

  • onInitialize(): essentially the area where variables will be initialized; this is called one time when the plugin is attached to an object instance.
  • onDeinitialize(): called once when the plugin is detached from an instance (or, by extension, if that instance is destroyed beforehand). Any cleanup of variables should be carried out in this event.
  • onActivate(): called once each time the plugin is activated.
  • onDeactivate(): called once each time the plugin is deactivated.

Continuous

  • main(): where most of the plugin's code will usually go; effectively the behavior itself.

API functions

  • selector:attachPlugin( STRING plugin_name ): attaches plugin then calls onInitialize()
  • selector:detachPlugin( STRING plugin_name ): calls onDeinitialize() then detaches plugin
  • selector:activatePlugin( STRING plugin_name ): calls onActivate() and resumes execution of plugin
  • selector:deactivatePlugin( STRING plugin_name ): calls onDeactivate() and suspends execution of plugin

Module list

(unfinished)

  • plugin.moves(): Object is affected by gravity, and has background collision and slope support. However, it does not make the object controllable by the player.
  • plugin.wraps(): Object will wrap around the level boundaries should it leave them.
  • plugin.pickup(): Object can be picked up and carried by the player