LunaLua global functions

From Moondust Wiki
Revision as of 17:03, 19 September 2015 by Kevsoft (talk | contribs)
Jump to navigation Jump to search

If you're still using LunaLua v6.* then please look on the bottom of the page for the old functions!

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)


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(object data, int x, int y) nil Prints data at x, y with font-type 3. data can be every lua object which supports the tostring operator. (Overworld and Level)
Text.print(object data, int type, int x, int 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.showMessageBox(string text) nil Displays a SMBX Message Box. (Level only)


Level functions (Level only)

Level Functions
Function Return values Description
Level.exit() nil Exit the level.
Level.filename() string Returns the filename of the level.
Level.name() string Returns the Title/Name of the level.
Level.winState() int Returns the current state of hitting the goal. If currently not winning then this value is 0.
Level.winState(int value) nil Sets the current state of hitting the goal. If currently not winning then this value is 0.
Level.loadPlayerHitBoxes(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.

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.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. (Overworld and Level)
getSMBXPath() string Returns the absolute path to smbx.exe. (Overworld and Level)

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.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.placeSprite(int type, LuaImageResource img, int xPos, int yPos) nil Places a sprite from the resource memory and places it at xPos, yPos (Overworld and Level)
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. (Overworld and Level)
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. (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, int xPos, int yPos) nil Draws the image resource for a frame. (LunaLua ≥ v0.7.1) (Overworld and Level)
Graphics.drawImage(LuaImageResource img, int xPos, int yPos, 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, int xPos, int yPos, int sourceX, int sourceY, int width, int 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, int xPos, int yPos, int sourceX, int sourceY, int width, int height, float 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.drawImageToScene(LuaImageResource img, int xPos, int yPos) nil Draws the image resource for a frame. The xPos and yPos are coordinates on the level/overworld. (LunaLua ≥ v0.7.1) (Overworld and Level)
Graphics.drawImageToScene(LuaImageResource img, int xPos, int yPos, float opacity) nil Draws the image resource for a frame, with an opacity from 0.0 to 1.0. The xPos and yPos are coordinates on the level/overworld. (LunaLua ≥ v0.7.1) (Overworld and Level)
Graphics.drawImageToScene(LuaImageResource img, int xPos, int yPos, int sourceX, int sourceY, int width, int 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 xPos and yPos are coordinates on the level/overworld. (LunaLua ≥ v0.7.1) (Overworld and Level)
Graphics.drawImageToScene(LuaImageResource img, int xPos, int yPos, int sourceX, int sourceY, int width, int height, float 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 xPos and yPos are coordinates on the level/overworld. (LunaLua ≥ v0.7.1) (Overworld and Level)
Graphics.unplaceSprites(LuaImageResource img) nil Removes all placed sprites with the same img resource. (Overworld and Level)
Graphics.unplaceSprites(LuaImageResource img, int xPos, int yPos) nil Removes all placed sprites with the same img resource and x-pos, y-pos (Overworld and Level)
Graphics.activateOverworldHud(number 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.

Static Item Functions

Static Block functions

Static Block Functions (Level only)
Function Return values Description
Block.count() number How many blocks are in the level.
Block.get() table of Block Returns all blocks
Block.get(number or table ids) table of Block Returns all blocks with the matching ids. Only the blocks with the same id given by ids will be returned.
Block.getIntersecting(number x1, number y1, number x2, number y2) table of Block Returns all blocks which are intersecting with an area from x1/y1 to x2/y2.


Static BGO functions

Static BGO Functions (Level only)
Function Return values Description
BGO.count() number How many BGOs are in the level.
BGO.get() table of BGO Returns all BGOs
BGO.get(number or table ids) table of BGO Returns all BGOs with the matching ids. Only the BGOs with the same id given by ids will be returned.
BGO.getIntersecting(number x1, number y1, number x2, number y2) table of BGO Returns all BGOs which are intersecting with an area from x1/y1 to x2/y2.


Static Camera functions

Static Camera Functions (Overworld and level)
Function Return values Description
Camera.get() table of BGO Returns all Cameras


Static Player functions

Static Player Functions (Overworld and level)
Function Return values Description
Player.count() number How many players are in the level.
Player.get() table of Player Returns all players. You might want to consider using the constants player and player2 instead!
Player.getTemplates() table of Player Returns all player templates. Player templates are the saved up player states for each character. They are saved, when the player hits a character-switch block. Modifing these templates and then hitting the character-switch blocks may give the result you expect.


Static Player Settings functions (Level only)

Static Player Settings Functions
Function Return values Description
PlayerSettings.get(number character, number powerup) PlayerSettings Returns a PlayerSettings object. With this object you can modify the hitbox and offset of the player directly. For character and powerup variable see constants.


Static NPC functions (Level only)

Static NPC Functions
Function Return values Description
NPC.count() number How many NPCs are in the level.
NPC.get() table of NPC Returns all NPCs
NPC.get(int or table ids, int or table sections) table of NPC Returns all NPC with the matching ids and section-numbers (0-20). Use -1 for ids or sections if you want to ignore this filter. Only the NPCs with the same id and sections given by ids and sections will be returned.
v0.7 has a critical bug crashing on this function! Be sure to be updated to 0.7.0.1!
NPC.getIntersecting(number x1, number y1, number x2, number y2) table of NPC Returns all NPCs which are intersecting with an area from x1/y1 to x2/y2.
NPC.spawn(int npcId, number x, number y, int sectionNumber) NPC Spawns a new npc. Note that sectionNumber is from 0-20 (-> Section 1 would be Section 0)
NPC.spawn(int npcId, number x, number y, int sectionNumber, boolean respawn) NPC Spawns a new npc. Note that sectionNumber is from 0-20 (-> Section 1 would be Section 0)
NPC.spawn(int npcId, number x, number y, int sectionNumber, boolean respawn, boolean centered) NPC Spawns a new npc. Note that sectionNumber is from 0-20 (-> Section 1 would be Section 0. If centered is true then x and y are the middle position of the spawning npc.)


Static Animation (SMBX Effect) functions (Level only)

Static Animation Functions
Function Return values Description
Animation.count() number How many effects are in the level.
Animation.get() table of Animation Returns all running effects.
Animation.get(number or table ids) table of Animation Returns all running effects with the matching ids. Only running effects with the same id given by ids will be returned.
Animation.getIntersecting(number x1, number y1, number x2, number y2) table of Animation Returns all effects which are intersecting with an area from x1/y1 to x2/y2.
Animation.spawn(int effectID, number x, number y) Animation Runs/Starts a new effect.)
Animation.spawn(int effectID, number x, number y, number animationFrame) Animation Runs/Starts a new effect. animationFrame is choosen effect frame (some effects have various version of a effect). NOTE: This Animation frame (as parameter) is not the same as Animation.animationFrame!


Static Layer functions (Level only)

Static Layer Functions
Function Return values Description
Layer.get() table of Layer Returns all existing layers.
Layer.get(string layerName) Layer Returns the layer object for the layerName. If no layer object with layerName is found then nil is returned.
Layer.find(string layerName) table of Layer Returns all layers containg the text layerName.


Static Level functions (Overworld only) [LunaLua v0.7.1.1]

Static Level Functions
Function Return values Description
Level.count() number Returns the number of levels on the overworld.
Level.get() table of Level Returns all levels on the overworld.
Level.get(number or table ids) table of Level Returns all levels with the matching item ids.
Level.getByName(string name) Level or nil Returns the level with the given level title. If the level is not found, then nil is returned.
Level.getByFilename(string name) Level or nil Returns the level with the given level filename. If the level is not found, then nil is returned.
Level.findByName(string searchText) table of Level Returns all levels where the level title contains searchText
Level.findByFilename(string searchText) table of Level Returns all levels where the level filename contains searchText


Static Warp functions (Level only)

Static Warp Functions
Function Return values Description
Warp.count() number How many warps are in the level.
Warp.get() table of Warp Returns all existing warps.
Warp.getIntersectingEntrance(number x1, number y1, number x2, number y2) table of Animation Returns all warps with an entrance intersecting with an area from x1/y1 to x2/y2.
Warp.getIntersectingExit(number x1, number y1, number x2, number y2) table of Animation Returns all warps with an exit intersecting with an area from x1/y1 to x2/y2.




Old Functions (for LunaLua v0.6.*)

Global Functions
Function Return values Description
windowDebug(string debugText) nil Writes debugText in a message box and shows it to the user.
printText(string text, int x, int y) nil Prints text at x, y with font-type 3
printText(string text, int type, int x, int y) nil Prints text at x, y with font-type type
totalNPC() int Returns the number of npcs.
npcs() table of NPC Returns a array of all NPCs.
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.
mem(int address, int fieldtype, object value) nil Sets the memory of the given type.
mem(int address, int fieldtype) object Returns the value of the given address of the given type.
triggerEvent(string eventName) nil Triggers a event by the given name
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.
loadImage(string filename, int resourceNumber, int transparentColor) nil Loads a image in the resource memory at resourceNumber. You can also set the transparent Color.
placeSprite(int type, int imgResource, int xPos, int yPos) nil Places a sprite from the resource memory and places it at xPos, yPos
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.
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.
gravity() int Returns the current gravity.
gravity(int value) nil Sets the current gravity.
earthquake() int Returns the current earthquake factor.
earthquake(int value) nil Sets the current earthquake factor. Slowly returns to 0!
jumpheight() int Returns the current jumpheight factor of all players.
jumpheight(int value) nil Sets the current jumpheight factor of all players.
jumpheightBounce() int Returns the current jumpheight factor (when bounced of a enemy) of all players.
jumpheightBounce(int value) nil Sets the current jumpheight factor (when bounced of a enemy) of all players.
blocks() table of Block Returns all blocks
findblocks(int ID) table of Block Returns all blocks with the specific id.
npcToCoins() nil Converts every npc on screen to coins. (Like you would hit the exit.)
animations() table of Animation Returns all running animations.
exitLevel() nil Exit the level.
winState() int Returns the current state of hitting the goal. If currently not winning then this value is 0.
winState(int value) nil Sets the current state of hitting the goal. If currently not winning then this value is 0.
runAnimation(int id, double x, double y, int extraData) nil DEPRECATED!!! Use spawnEffect function instead!
Runs a effect/animation by id. The parameter extraData should be 0, 1 or 1065353216 (you have to try out).
runAnimation(int id, double x, double y, double height, double width, int extraData) nil DEPRECATED!!! Use spawnEffect function instead!
Runs a effect/animation by id. The parameter extraData should be 0, 1 or 1065353216 (you have to try out).
runAnimation(int id, double x, double y, double height, double width, double speedX, double speedY, int extraData) nil DEPRECATED!!! Use spawnEffect function instead!
Runs a effect/animation by id. The parameter extraData should be 0, 1 or 1065353216 (you have to try out).
getInput() VBStr Get the cheat text buffer
hud(boolean showHud) nil Toggels the hud on/off
getLevelName() string Gets the level name/title.
getLevelFilename() string Gets the level filename.
spawnNPC(int npcid, double x, double y, int section) NPC Spawns a new NPC with the specific ID.
spawnNPC(int npcid, double x, double y, int section, boolean respawn) NPC Spawns a new NPC with the specific ID.
spawnNPC(int npcid, double x, double y, int section, boolean respawn, boolean centered) NPC Spawns a new NPC with the specific ID.
spawnEffect(int effectID, double x, double y) Animation Spawns a new Effect with the specific ID.
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 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.

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.