MPUZ: Plugins

From Mario Fan Games Galaxy Wiki
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 "gravity" would add gravity and related 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 = {
        ["gravity"] = "active",
        ["wrap"] = "inactive",
        ["carry"] = nil, -- detached (or never attached at all)
    },
    ...
}

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

  • onAttach(): essentially the area where variables will be initialized; this is called one time when the plugin is attached to an object instance.
  • onDetach(): 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 onAttach()
  • selector:detachPlugin( STRING plugin_name ): calls onDetach() 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)

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