Creating plugins

From Bitfighter
Revision as of 22:39, 27 December 2011 by Watusimoto (Talk | contribs)

Starting with version 016, it is possible to create level plugins with Lua. These plugins are currently fairly limited in functionality, but will be expanded in the future.


It is possible for the plugin to create a menu to get input from the user. There are currently 4 different menu widgets that can be added to a menu:

        CounterMenuItem:new("Angle", 90, 1, 0, 360, "deg.", "Disabled", "Sweep of arc", "Help me!"),          -- Name, value, step, min, max, units, minmsg, text, intvalue, 
        ToggleMenuItem:new("Toggleable", {"First", "Second", "Third"}, 1, false, "Pick one!"), -- Name, choices, selected index, wrap, help
        YesNoMenuItem:new("Hello",2,"Pick one"),                                               -- Name, selected index (1 = no, 2 = yes), help string
        TextEntryMenuItem:new("Text here", "start", "Empty", 20, "Enter your text")               -- Display Value, starting text, empty string, length, help

To create a menu, you must create a function in your script called getArgs(). That should return something like this:

-- Standard plugin method for building a menu to get parameters
function getArgs()
   local menuItem1 = CounterMenuItem:new(...)   -- Note the use of ':', NOT '.'
   local menuItem2 = YesNoMenuItem:new(...)
   local menuItem3 = TextEntryMenuItem:new(...)
 
   return "Menu Title",
      { menuItem1, menuItem2, menuItem3 }
end