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 RECTd Structure
Function Signature Info

myRect = RECTd()

Constructs a new RECT structure.

[double] myRect.left

The "left" value of the RECT structure.

[double] myRect.top

The "top" value of the RECT structure.

[double] myRect.right

The "right" value of the RECT structure.

[double] myRect.bottom

The "bottom" value of the RECT structure.

Same as RECT, just with double values.

 


The Section Class
Function Signature Info

mySection = Section([int] sectionnum)

Constructs a new section class by the sectionnumber.

[RECTd] myNPC.boundary

Holds the values for the section boundaries.

This class provides fields and functions to modify the section.


The NPC Class
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.

myNPC:mem([hex/int] address-offset, [int] datatype, [any] value)

Sets a NPC offset-address to a specfic value. See constants for datatypes.

[any] myNPC:mem([hex/int] address, [int] datatype)

Gets a specfic value by NPC offset-address. See constants for datatypes.

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.

[Section(readonly)] player.sectionObj

Returns the current section in a section object.

[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

player:mem([hex/int] address-offset, [int] datatype, [any] value)

Sets a player offset-address to a specfic value. See constants for datatypes.

[any] player:mem([hex/int] address, [int] datatype)

Gets a specfic value by player offset-address. See constants for datatypes.

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.

mem([hex/int] address, [int] datatype, [any] value)

Sets a global address to a specfic value. See constants for datatypes.

[any] mem([hex/int] address, [int] datatype)

Gets a specfic value by address. See constants for datatypes.

 

 

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

FIELD_BYTE

function mem

player:mem

myNPC:mem

Byte field data type

FIELD_WORD

function mem

player:mem

myNPC:mem

Word field data type

FIELD_DWORD

function mem

player:mem

myNPC:mem

DWord field data type

FIELD_FLOAT

function mem

player:mem

myNPC:mem

Float field data type

FIELD_DFLOAT

function mem

player:mem

myNPC:mem

DFloat field data type

 

Examples:

function onLoop()
  allNPCs = findnpcs(20,player.section)
  for k,v in pairs(allNPCs) do
    if(v.direction == DIR_RIGHT)then
      v.speedX = 5
    else
      v.speedX = -5

    end
  end
end

Info: Makes every blue Shy-Guy running super fast.


i = 0

function onLoad()
  i = 0
end

function onLoop()
  i = i + 1
  if(i % 100 == 0)then
    allNPCs = findnpcs(20,player.section)
    for k,v in pairs(allNPCs) do
      v.speedY = -8
    end
  end
end

Info: Makes every blue Shy-Guy jump every 100 frames.


function onLoop()
  if(player.y > -200320)then
    player.speedY = -10
  end
end

Info: Let the player jump up when it reaches a specific y-value.


i = 0

function onLoad()
  i = 0
end

function onLoop()
  printText("RUNNING "..tostring(i).." FRAMES", 30, 30)
  printText("PLAYER COOR "..tostring(player.x).." "..tostring(player.y), 30, 60)
end

Info: Some debug info.


i = 0

function onLoad()
  i = 0
end

function onLoop()
  i = i + 1
  if(i % 200 == 0)then
    player.powerup = math.random(1,7)
  end
end

Info: A new powerup every 200 frames (powerup roulett)