LunaLua events
Revision as of 15:52, 26 March 2022 by Yingchun Soul (talk | contribs)
This page shows Level and Overworld events.
Level functions
| Events | ||
|---|---|---|
| Function | Return values | Description |
| onStart() | nil | Runs the first frame of the level loading. (Level and Overworld) (LunaLua ≥ v0.7.3) |
| nil | onLoad is called when the level editor or the game engine loads the level. (Level and Overworld) | |
| onTick() | nil | This is called before SMBX gameplay logic each tick (right after onInputUpdate). (Level and Overworld) (LunaLua ≥ v0.7.3) |
| onTickEnd() | nil | This is called after SMBX gameplay logic each tick. (Level and Overworld) (LunaLua ≥ v0.7.3) |
| onDraw() | nil | This is called just before drawing each frame. (Level and Overworld) (LunaLua ≥ v0.7.3) |
| onDrawEnd() | nil | This is called just after drawing each frame. (Level and Overworld) (LunaLua ≥ v0.7.3) |
| nil | Immediately at the start of each frame while the game runs onLoop is called. (Level and Overworld) | |
| onLoopSection#(int playerIndex)*Obsoleted by the combination of onTick and if statement of Player.section | nil | On each frame while the game runs in the specific section # onLoopSection# is called. Replace # with the sectionnumber 0-20. Note: This function is called per player. If you are in 2-player-mode this function is called twice! (Level only) |
| onLoadSection(int playerIndex) | nil | In the first frameloop of a new section onLoadSection is called. Note: This function is called per player. If you are in 2-player-mode this function is called twice! (Level only) |
| onLoadSection#(int playerIndex) | nil | In the first frameloop of section # onLoadSection# is called. Replace # with the sectionnumber 0-20. Note: This function is called per player. If you are in 2-player-mode this function is called twice! (Level only) |
| onJump(int playerIndex) | nil | When the player starts to jump, onJump is called. playerIndex is the index of the player (Player 1: playerIndex = 1; Player 2: playerIndex = 2). Please note that only big jumps are recognized! (Level only) |
| onJumpEnd(int playerIndex) | nil | When the player hits the surface (jump ends), onJumpEnd is called. playerIndex is the index of the player (Player 1: playerIndex = 1; Player 2: playerIndex = 2). Please note that only big jumps are recognized! (Level only) |
| onKeyDown(int keycode, int playerIndex)*Obsoleted by Player.keys in onTick / onInputUpdate | nil | When a key is getting hit, onKeyDown is called. Keycode can be compared with the constants. playerIndex is the index of the player (Player 1: playerIndex = 1; Player 2: playerIndex = 2). (Level only) |
| onKeyUp(int keycode, int playerIndex)*Obsoleted by Player.keys in onTick / onInputUpdate | nil | When a key is getting released, onKeyUp is called. Keycode can be compared with the constants. playerIndex is the index of the player (Player 1: playerIndex = 1; Player 2: playerIndex = 2). (Level only) |
| onEvent(string eventName) | nil | This event is called when a SMBX event is called. (Level only) |
| onEventDirect(Event eventObj, string eventName) | nil | This event is called when a SMBX event is called. You can also cancel this event, meaning that the SMBX event will not processed by SMBX. NOTE: This function is not sync with the normal event loop. Changes in the SMBX memory may not affect or work with SMBX! (Level only) |
| onExitLevel() | nil | This event is called when the player exits the level (including exit by menu). (Level only) (LunaLua ≥v0.7) |
| onInputUpdate() | nil | This event is called every frame, like onTick, but you can overwrite the Player.**KeyPressing fields here! (Level and Overworld) (LunaLua ≥v0.7) |
| onMessageBox(Event eventObj, string message) | nil | This event is called before a message box is opened. (Level and Overworld) |
| onHUDDraw() | nil | This event is called when the HUD is drawn. (Level and Overworld) |
| onNPCKill(Event eventObj, NPC killedNPC, number killReason) | nil | This event is called when a NPC is killed. Killreasons: Note: in SMBX2 Beta 4 or later, if you don't wanna cancel events, use onPostNPCKill instead. (See Below) |
| onPostNPCKill(NPC killedNPC, number killReason) (SMBX2 Beta 4) | nil | Same as onNPCKill but for if you don't wanna cancel the event. |
| onCameraUpdate(Event eventObj, number cameraIndex) | nil | This event is called when the camera data is updated. With this event you can overwrite the camera data. (Level only) (LunaLua ≥ v0.7.3) |
| onKeyboardPress(number vk) | nil | This event is called when a key on the keyboard is pressed. vk is the virtual-key code. You can find more about the virtual-key code here: Virtual-Key Codes. You can directly use the constants given on this page including constants with letters and numbers (i.e. VK_4) (Level and Overworld). Note: Since there is no 'onKeyboardUp' event for all keys, you may want to use 'Misc.GetKeyState(keycode)' to check for key states. (LunaLua ≥ v0.7.3) |
| onKeyboardPressDirect(Event eventObj, number vk) | nil | This event is called when a key on the keyboard is pressed. Unlike onKeyboardPress, this event will work while the game is frozen with Misc.pause(). NOTE: This function is not sync with the normal event loop. Changes in the SMBX memory may not affect or work with SMBX! (Level and Overworld) (LunaLua ≥ v0.7.3) |