LunaDll for Lua Tutorial/Reference



Events:

Events are called by Lunadll if they exsist in the lua code.


Function Signature Info

function onLoad()

 

end

onLoad is called when the level editor or the game engine loads the level.

function onLoop()

 

end

On each frame while the game runs onLoop is called.

function onLoopSection#()

 

end

On each frame while the game runs in the specific section # onLoopSection# is called. Replace # with the sectionnumber 0-20.

function onLoadSection()

 

end

In the first frameloop of a new section onLoadSection is called.

function onLoadSection#()

 

end

In the first frameloop of section # onLoadSection# is called. Replace # with the sectionnumber 0-20.



Classes:

Classes are holding a bunch of functions, fields, ect... for a specific object type. They can be constructed or returned by a global function.

NOTE: The square brackets "[]" are used to indicate the return-type/param and are not part of the actual code. In lua, variables are defined without a variable-type.

The RECT Structure
Function Signature Info

myRect = RECT()

Constructs a new RECT structure.

[int] myRect.left

The "left" value of the RECT structure.

[int] myRect.top

The "top" value of the RECT structure.

[int] myRect.right

The "right" value of the RECT structure.

[int] myRect.bottom

The "bottom" value of the RECT structure.

This class provides fields to save "left", "top", "right", "bottom" as a int value. It is common used by other classes.


The NPC Structure
Function Signature Info

myNPC = NPC([int] arrayindex)

Constructs a new NPC via internal arrayindex.

NOTE: Do not construct directly. Use function "npcs()" or "findnpcs([int],[int])" instead!

[double] myNPC.x

The x value of the npc.

[double] myNPC.y

The y value of the npc.

[double] myNPC.speedX

The x speed value of the npc.

[double] myNPC.speedY

The y speed value of the npc.

[int] myNPC.id

The npc-id of the npc.

[int] myNPC.direction

The face direction of the npc.

NOTE: Setting the direction of a npc, resets the monumentum of the npc. You can modify the speedX value if you want to set your own monumentum.

This class provides fields and functions to modify the npc. It is not recommended to save this class for later, as the internal arrayindex changes when enemies get killed.



The Player Class
Function Signature Info

player = Player()

Constructs a new Player class. All constructed players will always point to the first player.

NOTE: It is recommended to use the constant "player" instead of constructing an own one.

player:kill()

Kills the player.

player:harm()

Harms the player (get a fake hit)

[double] player.x

The x value of the player.

[double] player.y

The y value of the player.

[double] player.speedX

The x speed value of the player.

[double] player.speedY

The y speed value of the player.

[int] player.powerup

The powerup value of the player.

[int] player.reservePowerup

The npc-id of the reserve powerup box.

[int(readonly)] player.section

The current section of the player.

[class RECT(readonly)] player.screen

The player RECT to the screen.

[class NPC(readonly) or nil] player.holdingNPC

If the player holds the npc, it returns the NPC

This class provides fields and functions to modify the player/character.

NOTE: It is recommended to use the constant "player" instead of constructing an own one.



Global functions:

Functions which can be globally accessed. They don't need any class to run.


Function Signature Info

windowDebug([string] text)

Displays a message box with the text provided.

printText([string] text, [int] x, [int] y)

Displays text at x,y with the font-type 3.

printText([string] text, [int] font-type, [int] x, [int y]

Displays text at x,y with the font-type of your choice.

[int] totalNPC()

Returns the number of NPCs in this level.

[NPC (array)] npcs()

Returns an array with all NPCs in this level.

[NPC (array)] findnpcs([int] npc-id, [int] section)

Returns an array filtered to npc-id and/or section. Use -1 or FIND_ANY to skip one of either filter.

 

 

Constants:

Constants are variables which hold values for specifc functions.


Constant Recommended use Info

FIND_ANY

function npcread

Ignores the filter of npcread

DIR_RIGHT

myNPC.direction

Direction right

DIR_RANDOM

myNPC.direction

Direction random

DIR_LEFT

myNPC.direction

Direction left

PLAYER_SMALL

player.powerup

No powerup/Small

PLAYER_BIG

player.powerup

Mushroom powerup/Big

PLAYER_FIREFLOWER

player.powerup

Fireflower powerup

PLAYER_LEAF

player.powerup

Leaf powerup

PLAYER_TANOOKIE

player.powerup

Tanookie powerup

PLAYER_HAMMER

player.powerup

Hammer powerup

PLAYER_ICE

player.powerup

Ice powerup