LunaLua events
Jump to navigation
Jump to search
| This is the archived page of the old LunaLua documentation The rest of LunaLua related articles in this wiki contain a lot of outdated documentation preserved for historical purposes and may be used with legacy versions of the LunaLua.
Please visit the SMBX2 Documentation Page to access the latest documentation for the LunaLua scripting system of the SMBX2 Project. Adding LunaLua contents into this Wiki is not advised. |
This page shows Level and Overworld events.
General functions
| Events | |||
|---|---|---|---|
| Function | Return values | Description | |
| onStart() | nil | Runs the first frame of the level loading. (Level and Overworld) (LunaLua ≥ v0.7.3) | |
| 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) | |
| onSectionChange(int sectionIndex, int playerIndex) | nil | Runs the code when player go to other section. (Level only; SMBX2 Beta 5+) | |
| onPause(Event eventObj, player playerindex) | nil | This event is called when the game is paused during normal gameplay (Instead of Testing levels). (Level and Overworld; SMBX2 Beta 4+) | |
| onEvent(string eventName) | nil | This event is called when a SMBX event is called, after next frame of "onLoop" (which is a predessor of "onTick"). (Level only) | |
| onEventDirect(Event eventObj, string eventName) | nil | This event is called instantly 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) | |
| onPostEventDirect(string eventName) | nil | Same as above, the exception is only run the code when the above event isn't cancelled. (Level only; SMBX2 Beta 4+) | |
| onWarp(warp warpObj, player player) | nil | Run the code after warping. (Level only; SMBX2 Beta 5+) | |
| onWarpEnter(Event eventObj, warp warpObj, player player) | nil | Run the code when player entering warp. (Level only; SMBX2 Beta 5+) | |
| onPostWarpEnter(warp warpObj, player player) | nil | Same as above, the exception is only run the code when the above event isn't cancelled. (Level only; SMBX2 Beta 5+) | |
| onSaveGame() | nil | Runs the code after game save. (SMBX2 Beta 5+) | |
| onExit() | nil | This event is called when the player exits the level or world map (including exit by menu). (SMBX2 Beta 5+) | |
| onExitLevel(number winType (SMBX2 Beta 4+)) | 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.keys.** fields here! (Level and Overworld) (LunaLua ≥v0.7) | |
| onMessageBox(Event eventObj, string message, player player, NPC TalkingNPC) | 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: Note: in SMBX2 Beta 4 or later, if you don't wanna cancel events, use onPostNPCKill instead. (See Below) | |
| onPostNPCKill(NPC killedNPC, number killReason) | nil | Same as onNPCKill but for if you don't wanna cancel the event. (SMBX2 Beta 4+) | |
| onPOW(Event eventObj) | nil | Run the code after hitting POW Block (Level Only; SMBX2 Beta 5+) | |
| onPostPOW() | nil | Same as above, but without cancellation. (Level Only; SMBX2 Beta 5+) | |
| onCameraUpdate(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 onDraw, 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).
| |
| onKeyboardPressDirect(number vk, boolean IsRepetitionByHolding , string character) | 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!
| |
| onKeyboardKeyPress(number vk, string keyName) | nil | Press a key to run the code. (Level and Overworld; SMBX2 Beta 5+) | |
| onKeyboardKeyRelease(number vk, string keyName) | nil | Release a key to run the code. (Level and Overworld; SMBX2 Beta 5+) | |
| onPasteText(string pastedText) | nil | Press Ctrl+V with the correspond text in the game to run the code. (Level and Overworld; SMBX2 Beta 4+) | |
Old functions
| Events | |||
|---|---|---|---|
| Function | Return values | Description | |
| onLoad() | nil | Predecessor of onStart function. onLoad is called when the level editor or the game engine loads the level. (Level and Overworld; use onStart) | |
| onLoop() | nil | Predecessor of onTick function. Immediately at the start of each frame while the game runs onLoop is called. (Level and Overworld; use onTick) | |
| onLoopSection#(int playerIndex) | nil | On each frame while the game runs in the specific section # onLoopSection# is called. Replace # with the sectionnumber 0-20.
| |
| onLoadSection(int playerIndex) | nil | In the first frameloop of a new section onLoadSection is called.
| |
| onLoadSection#(int playerIndex) | nil | In the first frameloop of section # onLoadSection# is called. Replace # with the sectionnumber 0-20.
| |
| 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; Put Player state checkments (e.g. player.keys.jump) inside onTick or onTickEnd) | |
| 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; Put Player state checkments (e.g. player:isOnGround() or player:isGroundTouching()) inside onTick or onTickEnd) | |
| 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; Put Player key checkments (player.keys) inside onTick or onInputUpdate) | |
| 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; Put Player key checkments (player.keys) inside onTick or onInputUpdate) | |