Commander.lua (Merge of command and commando)

Share and discuss custom LunaLua code and content packs for SMBX2.

Moderator: Userbase Moderators

Yoshi021
Gold Yoshi Egg
Gold Yoshi Egg
Posts: 691
Joined: Thu Jan 21, 2016 9:06 pm
Flair: :)
Pronouns: He/Him

Commander.lua (Merge of command and commando)

Postby Yoshi021 » Sun Jun 28, 2020 10:52 pm

Hello! Commander.lua is a library aim at helping you read inputs and organize the information easily and conveniently to use!

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    
    },
}
How to register a player 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.
How to register a keyboard key

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
Using a commander key
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
prevstate The state of the key in the previous frame
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!
Last edited by Yoshi021 on Thu Jul 02, 2020 10:16 am, edited 1 time in total.

arhi998
Cheep-Cheep
Cheep-Cheep
Posts: 11
Joined: Sun Oct 21, 2018 5:00 am
Flair: Hi everyone! i'm just a normal dude playing smbx.

Re: Command.lua and Commando.lua

Postby arhi998 » Mon Jun 29, 2020 3:03 am

Nice! Could be very useful for beginners too. (like me)

Taycamgame
Gold Yoshi Egg
Gold Yoshi Egg
Posts: 1483
Joined: Mon Jun 19, 2017 11:35 am
Flair: Stargard
Contact:

Re: Command.lua and Commando.lua

Postby Taycamgame » Mon Jun 29, 2020 7:19 am

These are both certainly going to be useful, though I wouldn't be surprised if people typically make more use of Commando due to the added functionality of allowing any key to be an input!

Novarender
Tweeter
Tweeter
Posts: 145
Joined: Sat Aug 06, 2016 6:59 pm
Flair: Whoa

Re: Command.lua and Commando.lua

Postby Novarender » Mon Jun 29, 2020 10:55 am

So did you fix the issue of not being able to detect key releases from non-player inputs?

Yoshi021
Gold Yoshi Egg
Gold Yoshi Egg
Posts: 691
Joined: Thu Jan 21, 2016 9:06 pm
Flair: :)
Pronouns: He/Him

Re: Command.lua and Commando.lua

Postby Yoshi021 » Mon Jun 29, 2020 12:16 pm

Yes!

Yoshi021
Gold Yoshi Egg
Gold Yoshi Egg
Posts: 691
Joined: Thu Jan 21, 2016 9:06 pm
Flair: :)
Pronouns: He/Him

Re: Commander.lua (Merge of command and commando)

Postby Yoshi021 » Thu Jul 02, 2020 10:16 am

I merged both libraries into one. Now you don't have to pick one over the other!


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 3 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari