LunaLua global functions

From PGE Wiki
Jump to: navigation, search


General functions

Global Functions
Function Return values Description
mem(int address, int fieldtype, object value) nil Sets the memory of the given type. (Overworld and Level)
mem(int address, int fieldtype) object Returns the value of the given address of the given type. (Overworld and Level)
checkLunaVersion(...) number Compares the given luna version if it is older or newer than the current build. If the version number is older then -1 is returned. If the given version number is newer then 1 is returned. If the given version number are the same, then 0 is returned.
Example:
local result = checkLunaVersion(0, 7, 3, 0) -- Would return 0 if the LunaLua build was 0.7.3
(LunaLua ≥ v0.7.3) (Overworld and Level)


Text functions

Text Functions
Function Return values Description
Text.windowDebug(string debugText) nil Writes debugText in a message box and shows it to the user. (Overworld and Level)
Text.print(string, number x, number y) nil Prints data at x, y with font-type 3. Characters are, by default, each 18px wide and 20px high. data can be every lua object which supports the tostring operator. (Overworld and Level)
Text.print(string, int type, number x, number y) nil Prints data at x, y with font-type type. data can be every lua object which supports the tostring operator. (Overworld and Level)
Text.printWP(string, number x, number y, number priority) nil Prints data at x, y with font-type 3. data can be every lua object which supports the tostring operator. The rendering of the text is prioritized. Read more about the LunaLua Render Priority. (Overworld and Level)
Text.printWP(string, int type, number x, number y, number priority) nil Prints data at x, y with font-type type. data can be every lua object which supports the tostring operator. The rendering of the text is prioritized. Read more about the LunaLua Render Priority. (Overworld and Level)
Text.showMessageBox(string) nil Displays a SMBX Message Box. (Level only)

Misc functions

Misc Functions
Function Return values Description
Misc.npcToCoins() nil Converts every npc on screen to coins. (Like you would hit the exit.) (Level only)
Misc.doPOW() nil Starts the "POW"-Effect (like if the POW-Block hits the floor) (Level only)
Misc.cheatBuffer() string Gets the current cheat buffer text. (Overworld and Level)
Misc.cheatBuffer(string cheatBufferText) nil Sets the current cheat buffer text. (Overworld and Level)
Misc.listFiles(string path) table of string Returns a list of files in the given path. The paths starts from the SMBX-Directory. If path is an empty string, then the files in the SMBX-Directory are returned. (Overworld and Level)
Misc.listLocalFiles(string path) table of string Returns a list of files in the given path. The paths starts from the custom folder of the level (when in a level) or the current episode folder (when in the overworld). If path is an empty string, then the files in the custom folder (or episode folder when in overworld) are returned. If you want to access the episode folder from the level code you can use Misc.listLocalFiles(".."). (Overworld and Level)
Misc.resolveFile(string path) string or nil Searches for a file given by the path in following directories:
  • Custom level folder
  • Episode folder
  • {SMBX root path}/LuaScriptsLib
  • {SMBX root path}
... in that order. The full absoulte path will be returned or nil if not found. (LunaLua ≥ v0.7.1) (Overworld and Level)
Misc.resolveGraphicsFile(string path) string or nil Searches for a file given by the path in following directories:
  • Custom level folder
  • Episode folder
  • {SMBX root path}/graphics
... in that order. The full absoulte path will be returned or nil if not found. (LunaLua ≥ v0.7.3.1) (Overworld and Level)
Misc.resolveDirectory(string path) string or nil Searches for a directory given by the path in following directories:
  • Custom level folder
  • Episode folder
  • {SMBX root path}/LuaScriptsLib
  • {SMBX root path}
... in that order. The full absoulte path will be returned or nil if not found. (LunaLua ≥ v0.7.1) (Overworld and Level)
Misc.openPauseMenu() nil Opens the pause menu.
Fun fact: Kevsoft implemented that while trying to implement the Misc.loadEpisode function. Only recommended for trolling! (Overworld and Level)
Misc.saveGame() nil Saves the game to the current save slot. (Overworld and Level)
Misc.exitGame() nil Exits the game to the main menu. (Overworld and Level)
Misc.loadEpisode(string episodeTitle) boolean Loads another episode given by the episode title. If the episode was not found then false is returned. If succeeded, then true is returned. However the actual episode switch is done, when SMBX gets the control back from LunaLua. Additional code may run after the Misc.loadEpisode function. Also note that holding the run button may interrupt the process and the game may stay at the title screen. (Overworld and Level)
Misc.doBombExplosion(number x, number y, number type) nil Will do a bomb explosion. For type you can use following values:

0 - Peach bomb
2 - SMB2 explosion
3 - SMB3 explosion

(LunaLua ≥ v0.7.2.3) (Level)
Misc.doBombExplosion(number x, number y, number type, Player fromPlayer) nil Will do a bomb explosion. fromPlayer is used for the peach bomb in battle mode (The other players will take damage). For type you can use following values:

0 - Peach bomb
2 - SMB2 explosion
3 - SMB3 explosion

(LunaLua ≥ v0.7.2.3) (Level)
Misc.doPSwitch() nil This will execute or stop the full P-Switch effect (including music and timer), depending on the P-Switch timer. If the P-Switch effect is not active, then this function will activate it. Otherwise it will stop this effect.(LunaLua ≥ v0.7.2.3) (Level)
Misc.doPSwitch(boolean activate) nil This will execute or stop the full P-Switch effect (including music and timer), depending on the activate parameter.(LunaLua ≥ v0.7.2.3) (Level)
Misc.doPSwitchRaw(boolean activate) nil This will execute the raw P-Switch effect. Neither music nor the P-Switch timer is affected. (LunaLua ≥ v0.7.2.3) (Level)
Misc.pause() nil This will pause the whole game. (LunaLua ≥ v0.7.3) (Overworld and Level)
Misc.unpause() nil This will unpause the whole game. (LunaLua ≥ v0.7.3) (Overworld and Level)
Misc.isPausedByLua() boolean If the whole game is paused via Misc.pause (LunaLua ≥ v0.7.3) (Overworld and Level)
getSMBXPath() string Returns the absolute path to smbx.exe. (Overworld and Level)
triggerEvent(string eventName) nil Triggers an SMBX event by the given name. (Level Only)

Graphics functions


Graphics Functions
Function Return values Description
Graphics.activateHud(boolean showHud) nil Toggels the hud on/off (Level only)
Graphics.loadImage(string filename) LuaImageResource Loads a image in the resource memory, returning a reference to it. (Overworld and Level)
Graphics.loadImageResolved(string filename) LuaImageResource Searches for a file given by the path in following directories:
  • Custom level folder
  • Episode folder
  • {SMBX root path}/graphics
... in that order and loads it in the resource memory, returning a reference to it. (Overworld and Level) (LunaLua ≥ v0.7.3.1)
Graphics.loadAnimatedImage(string filename) table of LuaImageResource, number Loads an animated image (i.e. gifs) and returns a table of each frame in the animated image. The second return argument is the average frame speed (SMBX frames per frame switch) given by the gif metadata. If no gif metadata is found then the average speed is 0.09s * 65 SMBX frames. (Overworld and Level)
Graphics.getPixelData(LuaImageResource img) table of number, number, number Extracts all image data from the image resources in an array with the BGRA-Format.

The first return-value is the array with BGRA pixel values (is width * height * 4 big)
The second return-value is the width
The third return-value is the height

(LunaLua ≥ v0.7.1) (Overworld and Level)
Graphics.drawImage(LuaImageResource img, number x, number y) nil Draws the image resource for a frame. (LunaLua ≥ v0.7.1) (Overworld and Level)
Graphics.drawImage(LuaImageResource img, number x, number y, float opacity) nil Draws the image resource for a frame, with an opacity from 0.0 to 1.0. (LunaLua ≥ v0.7.1) (Overworld and Level)
Graphics.drawImage(LuaImageResource img, number x, number y, number sourceX, number sourceY, number width, number height) nil Draws the image resource for a frame. Only a part of the pictures is drawn given by sourceX and sourceY with the specific width and height. (LunaLua ≥ v0.7.1) (Overworld and Level)
Graphics.drawImage(LuaImageResource img, number x, number y, number sourceX, number sourceY, number width, number height, number opacity) nil Draws the image resource for a frame, with an opacity from 0.0 to 1.0. Only a part of the pictures is drawn given by sourceX and sourceY with the specific width and height. (LunaLua ≥ v0.7.1) (Overworld and Level)
Graphics.drawImageWP(LuaImageResource img, number x, number y, number priority) nil Draws the image resource for a frame. The rendering of the image is prioritized. Read more about the LunaLua Render Priority. (LunaLua ≥ v0.7.2) (Overworld and Level)
Graphics.drawImageWP(LuaImageResource img, number x, number y, number opacity, number priority) nil Draws the image resource for a frame, with an opacity from 0.0 to 1.0. The rendering of the image is prioritized. Read more about the LunaLua Render Priority. (LunaLua ≥ v0.7.2) (Overworld and Level)
Graphics.drawImageWP(LuaImageResource img, number x, number y, number sourceX, number sourceY, number width, number height, number priority) nil Draws the image resource for a frame. Only a part of the pictures is drawn given by sourceX and sourceY with the specific width and height. The rendering of the image is prioritized. Read more about the LunaLua Render Priority. (LunaLua ≥ v0.7.2) (Overworld and Level)
Graphics.drawImageWP(LuaImageResource img, number x, number y, number sourceX, number sourceY, number width, number height, number opacity, number priority) nil Draws the image resource for a frame, with an opacity from 0.0 to 1.0. Only a part of the pictures is drawn given by sourceX and sourceY with the specific width and height. The rendering of the image is prioritized. Read more about the LunaLua Render Priority. (LunaLua ≥ v0.7.2) (Overworld and Level)
Graphics.drawImageToScene(LuaImageResource img, number x, number y) nil Draws the image resource for a frame. The x and y are coordinates on the level/overworld. (LunaLua ≥ v0.7.1) (Overworld and Level)
Graphics.drawImageToScene(LuaImageResource img, number x, number y, number opacity) nil Draws the image resource for a frame, with an opacity from 0.0 to 1.0. The x and y are coordinates on the level/overworld. (LunaLua ≥ v0.7.1) (Overworld and Level)
Graphics.drawImageToScene(LuaImageResource img, number x, number y, number sourceX, number sourceY, number width, number height) nil Draws the image resource for a frame. Only a part of the pictures is drawn given by sourceX and sourceY with the specific width and height. The x and y are coordinates on the level/overworld. (LunaLua ≥ v0.7.1) (Overworld and Level)
Graphics.drawImageToScene(LuaImageResource img, number x, number y, number sourceX, number sourceY, number width, number height, number opacity) nil Draws the image resource for a frame, with an opacity from 0.0 to 1.0. Only a part of the pictures is drawn given by sourceX and sourceY with the specific width and height. The x and y are coordinates on the level/overworld. (LunaLua ≥ v0.7.1) (Overworld and Level)
Graphics.drawImageToSceneWP(LuaImageResource img, number x, number y, number priority) nil Draws the image resource for a frame. The x and y are coordinates on the level/overworld. The rendering of the image is prioritized. Read more about the LunaLua Render Priority. (LunaLua ≥ v0.7.2) (Overworld and Level)
Graphics.drawImageToSceneWP(LuaImageResource img, number x, number y, number opacity, number priority) nil Draws the image resource for a frame, with an opacity from 0.0 to 1.0. The x and y are coordinates on the level/overworld. The rendering of the image is prioritized. Read more about the LunaLua Render Priority. (LunaLua ≥ v0.7.2) (Overworld and Level)
Graphics.drawImageToSceneWP(LuaImageResource img, number x, number y, number sourceX, number sourceY, number width, number height, number priority) nil Draws the image resource for a frame. Only a part of the pictures is drawn given by sourceX and sourceY with the specific width and height. The x and y are coordinates on the level/overworld. The rendering of the image is prioritized. Read more about the LunaLua Render Priority. (LunaLua ≥ v0.7.2) (Overworld and Level)
Graphics.drawImageToSceneWP(LuaImageResource img, number x, number y, number sourceX, number sourceY, number width, number height, number opacity, number priority) nil Draws the image resource for a frame, with an opacity from 0.0 to 1.0. Only a part of the pictures is drawn given by sourceX and sourceY with the specific width and height. The x and y are coordinates on the level/overworld. The rendering of the image is prioritized. Read more about the LunaLua Render Priority. (LunaLua ≥ v0.7.2) (Overworld and Level)
Graphics.activateOverworldHud(int worldHudType) nil Manages the overworld hud control. Following values can be used:

WHUD_ALL - All hud elements are visible.
WHUD_ONLY_OVERLAY - Only the hud overlay is visible. Text and icons are hidden.
WHUD_NONE - No overlay, text or icons are visible.

(World only)
Graphics.isOpenGLEnabled() boolean Returns whether the OpenGL renderer is active or not.
Graphics.isHudActivated() boolean Returns if the default Level HUD is activated. (Level only)
Graphics.getOverworldHudState() int Returns if the overworld state. Following values can be returned:

WHUD_ALL - All hud elements are visible.
WHUD_ONLY_OVERLAY - Only the hud overlay is visible. Text and icons are hidden.

WHUD_NONE - No overlay, text or icons are visible.
(LunaLua ≥ v0.7.2) (Overworld only)
Graphics.sprites.####[*] SpriteOverride Accesses an overrideable graphic. With this function you can overwrite SMBX graphics at runtime.

#### represents the graphics group. The different graphics groups are named after the folders in the graphics folder.
* is the id of the object.
See more: SpriteOverride class

(Level and Overworld) (LunaLua ≥ v0.7.3.1)
(Level only in LunaLua 0.7.3)
Graphics.draw{Named Args} nil This function accepts a table with named arguments for drawing purpose. (LunaLua ≥ v0.7.3)
Graphics.glDraw{Named Args} nil This function accepts a table with named arguments for OpenGL drawing operations. (LunaLua ≥ v0.7.3)




Deprecated

Deprecated Global Functions
Function Return values Description
windowDebug(string debugText) nil Writes debugText in a message box and shows it to the user. (Deprecated: Use Text.windowDebug)
printText(string text, int x, int y) nil Prints text at x, y with font-type 3 (Deprecated: Use Text.print)
printText(string text, int type, int x, int y) nil Prints text at x, y with font-type type (Deprecated: Use Text.print)
totalNPC() int Returns the number of npcs. (Deprecated: Use NPC.count)
npcs() table of NPC Returns a array of all NPCs. (Deprecated: Use NPC.get)
findnpcs(int ID, string section) table of NPC Searches all npcs by ID and Section. Use -1 as a parameter to ingore the given filter. (Deprecated: Use NPC.get)
loadHitboxes(int characterId, int powerUpId, string iniFilename) nil Loads the hitbox settings for specific player and it's power-up state from INI file made by Special Calibration tool.
Note: GFX-offsets of each frame are not overwritable yet. Use image calibration to calibrate position of frame without editing of GFX offsets.(Deprecated: Use Level.loadPlayerHitBoxes)
loadImage(string filename, int resourceNumber, int transparentColor) nil Loads a image in the resource memory at resourceNumber. You can also set the transparent Color. (Deprecated: Use Graphics.loadImage)
placeSprite(int type, int imgResource, int xPos, int yPos) nil Places a sprite from the resource memory and places it at xPos, yPos. (Deprecated: Use Graphics.draw or Graphics.drawImageWP)
placeSprite(int type, int imgResource, int xPos, int yPos, string extra) nil Places a sprite from the resource memory and places it at xPos, yPos. (Deprecated: Use Graphics.draw or Graphics.drawImageWP)
placeSprite(int type, int imgResource, int xPos, int yPos, string extra, int time) nil Places a sprite from the resource memory and places it at xPos, yPos. (Deprecated: Use Graphics.draw or Graphics.drawImageWP)
Graphics.placeSprite(int type, LuaImageResource img, int xPos, int yPos) nil Places a sprite from the resource memory and places it at xPos, yPos. (Deprecated: Use Graphics.draw or Graphics.drawImageWP)
Graphics.placeSprite(int type, LuaImageResource img, int xPos, int yPos, string extra) nil Places a sprite from the resource memory and places it at xPos, yPos. (Deprecated: Use Graphics.draw or Graphics.drawImageWP)
Graphics.placeSprite(int type, LuaImageResource img, int xPos, int yPos, string extra, int time) nil Places a sprite from the resource memory and places it at xPos, yPos. (Deprecated: Use Graphics.draw or Graphics.drawImageWP)
Graphics.unplaceSprites(LuaImageResource img) nil Removes all placed sprites with the same img resource. (Deprecated)
Graphics.unplaceSprites(LuaImageResource img, int xPos, int yPos) nil Removes all placed sprites with the same img resource and x-pos, y-pos. (Deprecated)
gravity() int Returns the current gravity. (Deprecated: Use Defines.gravity)
gravity(int value) nil Sets the current gravity. (Deprecated: Use Defines.gravity)
earthquake() int Returns the current earthquake factor. (Deprecated: Use Defines.earthquake)
earthquake(int value) nil Sets the current earthquake factor. Slowly returns to 0! (Deprecated: Use Defines.earthquake)
jumpheight() int Returns the current jumpheight factor of all players. (Deprecated: Use Defines.jumpheight)
jumpheight(int value) nil Sets the current jumpheight factor of all players. (Deprecated: Use Defines.jumpheight)
jumpheightBounce() int Returns the current jumpheight factor (when bounced of a enemy) of all players. (Deprecated: Use Defines.jumpheight_bounce)
jumpheightBounce(int value) nil Sets the current jumpheight factor (when bounced of a enemy) of all players. (Deprecated: Use Defines.jumpheight_bounce)
blocks() table of Block Returns all blocks (Deprecated: Use Block.get)
findblocks(int ID) table of Block Returns all blocks with the specific id. (Deprecated: Use Block.get)
npcToCoins() nil Converts every npc on screen to coins. (Like you would hit the exit.) (Deprecated: Use Misc.npcToCoins)
animations() table of Animation Returns all running animations. (Deprecated: Use Animation.get)
exitLevel() nil Exit the level. (Deprecated: Use Level.exit)
winState() int Returns the current state of hitting the goal. If currently not winning then this value is 0. (Deprecated: Use Level.winState)
winState(int value) nil Sets the current state of hitting the goal. If currently not winning then this value is 0. (Deprecated: Use Level.winState)
runAnimation(int id, double x, double y, int extraData) nil Runs a effect/animation by id. The parameter extraData should be 0, 1 or 1065353216 (you have to try out). (Deprecated: Use Animation.spawn)
runAnimation(int id, double x, double y, double height, double width, int extraData) nil Runs a effect/animation by id. The parameter extraData should be 0, 1 or 1065353216 (you have to try out). (Deprecated: Use Animation.spawn)
runAnimation(int id, double x, double y, double height, double width, double speedX, double speedY, int extraData) nil Runs a effect/animation by id. The parameter extraData should be 0, 1 or 1065353216 (you have to try out). (Deprecated: Use Animation.spawn)
getInput() VBStr Get the cheat text buffer (Deprecated: Use Misc.cheatBuffer)
hud(boolean showHud) nil Toggels the hud on/off (Deprecated: Use Graphics.activateHud)
getLevelName() string Gets the level name/title. (Deprecated: Use Level.name)
getLevelFilename() string Gets the level filename. (Deprecated: Use Level.filename)
spawnNPC(int npcid, double x, double y, int section) NPC Spawns a new NPC with the specific ID. (Deprecated: Use NPC.spawn)
spawnNPC(int npcid, double x, double y, int section, boolean respawn) NPC Spawns a new NPC with the specific ID. (Deprecated: Use NPC.spawn)
spawnNPC(int npcid, double x, double y, int section, boolean respawn, boolean centered) NPC Spawns a new NPC with the specific ID. (Deprecated: Use NPC.spawn)
spawnEffect(int effectID, double x, double y) Animation Spawns a new Effect with the specific ID. (Deprecated: Use Animation.spawn)
spawnEffect(int effectID, double x, double y, number animationFrame) Animation Spawns a new Effect with the specific ID and Animation Frame.
NOTE: This Animation frame (as parameter) is not the same as Animation.animationFrame! (Deprecated: Use Animation.spawn)


DEPRECATED!!! Use Data class instead!


The UserData-Namespace gives your access to the variable bank. With variable bank you can save number-values for other levels and when the game closes.

Deprecated Global Functions [UserData Namespace]
Function Return values Description
UserData.setValue(string key, number value) nil Sets a number-value by a specfic key.
UserData.getValue(string key) number or nil Gets a number-value by a specfic key. If value is not set then nil is returned.
UserData.isValueSet(string key) boolean If value is not set then false is returned. Otherwise true.
UserData.values() table with key=string value=number Returns a table with all mapped values of the variable bank.
UserData.save() nil Writes all the data in the variable txt-file.