LunaLua events

From PGE Wiki
Jump to: navigation, 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() nil *DEPRECATED* (use onStart instead if you're using LunaLua ≥ V0.7.3) 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)
onLoop() nil *DEPRECATED* (Use onTick instead if you're using LunaLua ≥ V0.7.3) Immediately at the start of each frame while the game runs onLoop is called. (Level and Overworld)
onLoopSection#(int playerIndex) 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) 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) 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:
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)
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) (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)