LunaLua events

From Moondust Wiki
Jump to navigation Jump to search


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)
onLoad()*Use onStart, see above nil onLoad is called when the level editor or the game engine loads the level. (Level and Overworld)
OOjs UI icon notice-destructive.svg DEPRECATED: Must use onStart!
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)
onLoop()*Use onTick nil Immediately at the start of each frame while the game runs onLoop is called. (Level and Overworld)
OOjs UI icon notice-destructive.svg DEPRECATED: Must use onTick!
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)
OOjs UI icon notice-destructive.svg DEPRECATED: Use player state checkments in onTick or onTickEnd events instead.
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)
OOjs UI icon notice-destructive.svg DEPRECATED: Use player state checkments in onTick or onTickEnd events instead.
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)
OOjs UI icon notice-destructive.svg DEPRECATED: Use player.keys checkment in onTick or onInputUpdate events instead.
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)
OOjs UI icon notice-destructive.svg DEPRECATED: Use player.keys checkment in onTick or onInputUpdate events instead.
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(number cameraIndex (SMBX2 Beta 4+)) 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:
1 - Default kill
2 - Bonked from Below
3 - Shell, bomb, squish, hammer, most thrown NPCs
4 - Projectile hitting something else (the NPC referred to being projectile itself in this case, not what it hit)
5 - Killed by some types of enemy being held by the player (not a thrown enemy)
6 - Lava
7 - Tail kill
8 - Spinjump
9 - Despawn or NPC eaten (ie powerups) = Vanish
10 - Link Slash or Link Fireball

(Level only) (LunaLua ≥ v0.7.2.3)
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)
onCameraDraw(number cameraIndex) nil Same as onTick, but this is for camera index. (Level only) (SMBX2 Beta 4+)
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)