Documentation
As of now, commander can read inputs from player inputs and keyboard inputs.
Creating a command key
To create a command key, you simply use the commmander.register function. You must supply a table like this:
Code: Select all
local command = require("command")
-- Register your keys
command.register{
[1] = { -- This represents the command keys for input 1
up ={ID = 1, name = "up"}, -- You can now access this input by doing commander[1].up
down = {ID = 1, name = "down"},
left = {ID = 1, name = "left"},
right = {ID = 1, name = "right"},
jump = {ID = 1, name = "jump"},
dash = {ID = 1, name = "run"}, -- You can now access this input by doing commander[1].dash. Note how its inputs are based off the run key.
pause = 32, -- 32 is the vk code for the space key
},
[2] = { -- This represents the command keys for input 2
up = {ID = 2, name = "up"}, -- You can now access this input by doing commander[2].up
down = {ID = 2, name = "down"},
left = {ID = 2, name = "left"},
right = {ID = 2, name = "right"},
jump = {ID = 2, name = "jump"},
dash = {ID = 2, name = "run"},
pause = 20, -- 20 is the vk code for the caps lock key
},
}
Code: Select all
-- name has to be "up", "down", "left", "right", "run", "altRun", "jump", "altJump", "dropItem", "pause"
myKey = {name = "up"} -- This is the bare minimum for a player key. It will assume player 1 inputs
myKey = {name = "up, ID = 1} -- Use the ID field to specify which player you want the inputs from. Use 1 for players, and 2 for player 2
myKey = {name = "up", ID = 1, mode = "keys"} -- By default mode is "rawKeys". Set the mode to "keys if you want to. The difference is that keys is affected when disabling player inputs and note that run is activated most of the time when pressing altRun.
myKey = {name = "up", ID = 1, mode = "keys", type = commander.TYPE_PLAYERKEY} -- You can use type to specify that its a player me, but by default its assumed to be.
Code: Select all
myKey = 32 -- Just putting a number will make the script assume its a keyboard key
myKey = {ID= 32, type= TYPE_KEYBOARD} -- You can also specify a keyboard key like this
A commander key has four different keys you can access.
state To be used with KEYS_PRESSED, KEYS_RELEASED, KEYS_DOWN, KEYS_UP.
time Measures how long a key has been held or released. Counts up when pressed, and counts down when released. Gets set to 1 or -1 when a key is pressed or released respectively. Example:
Code: Select all
local v = commander[1].myCustomKey.time
v == 30 -- if the key is held for exactly 30 frames
v > 30 -- if the key is held for longer 30 frames
v == -30 -- if the key is not held for exactly 30 frames
v < -30 -- if the key is not held for longer 30 frames
v == 1 -- Equivalent to checking if a key is KEYS_PRESSED
v == -1 -- Equivalent to checking if a key is KEYS_RELEASED
time The time in the previous frame
Download
Commander.lua
TL;DR this library allows you to get standard SMBX inputs, give it a nickname and get the state, and how long the key was held and released.
Please report any bugs you find and feel free to leave suggestions!