Functions

addDisplay

  • in string name
  • in int x
  • in int y
  • in int type
  • out Display
This function is similar to addDisplayC excepts that it returns a Display object.

After adding a new Display object also remember to set it visible using the Display:setVisible method.

DISPLAY_TIME_LEFT   
displays the timeLeft counter 
 
DISPLAY_MESSAGE
displays a text message
 
DISPLAY_SCORE       
displays the user score 
 
DISPLAY_LIVES      
display available lives 
 
DISPLAY_HP         
display the hp counter  
 
DISPLAY_DEBUG	
displays the debug console

when a game is run there are already several displays defined. you may modify these displays using getDisplay() with the appropriate name string.

example

local displayId; 
 
displayId = findDisplay("timeLeft");
debug("timeLeft id: " .. displayId); 
 
displayId = findDisplay("score");
debug("score id: " .. displayId); 
 
local timeLeft = getDisplayByName("timeLeft");
timeLeft:setColor(0xff, 0xff, 0, 0x80);
timeLeft:move(SCREENLEN - 100, 0);
timeLeft:setFontSize(50); 
 
local score = getDisplayByName("score");
score:setColor(0xff, 0xff, 0xff, 0x80);
score:setFontSize(24); 
 
local t = addDisplay("test", 64, 64, DISPLAY_MESSAGE);
t:setText("this is a test\nSonia and the Pumpkins");
t:show();

addLayer

  • in string name
  • in int type
  • in int hSpeed*
  • in int vSpeed*
  • out Layer
see layer_new

in parameter hSpeed : optional and can be omitted.

in parameter vSpeed : optional and can be omitted.


addSprite

  • in int x
  • in int y
  • in int imageSet
  • in int imageNo
  • in int aim
  • in int objectType
  • in int imageSet*
  • in int imageNo*
  • out Sprite
note: modifying variables inside of sprite doesn't change the object on screen only your own local copy. to alter the sprite, use the build-in methods. see getSprite for more details

in parameter imageSet : optional and can be omitted.

in parameter imageNo : optional and can be omitted.


addToHP

  • in int hitPoints
  • out int
negative values will be substracted. if the modication causes the player to fall under 0 hp. the player dies. therefor onDeath will also be called

addToHP will check for over bound value. if the player goes over maxHP, the value will be adjusted automatically

this function will also update the hp counter on screen


addToInventory

  • in int objectType
  • out void
Add an object to the inventory of the player.

addToScore

  • in int points
  • out int current score
add points to the player's score. this the function to use if you want to bypass the autogenerated point that fly to the top of the screen.

also note that if the value is negative, it will get deducted from the total no test is performed to check for negative scores or overflow


alert

  • in string text
  • out void
Create a standard message box with an okay button to display the text. Works just like the alert() function in javascript.

alert("welcome home");

AND

  • in int a
  • in int b
  • out int
Binary AND operator. Take bitwise equivalence of bits that are switched on in both integers.

callGameEvent

  • in int eventId
  • out void
Call a game event to let the engine know that it must be handled now. This is a list of valid events:
EG_INIT_GAME
    EG_PREPARE_LEVEL    
    EG_COMPLETE_LEVEL 
    EG_DEATH           
    EG_GOAL_COLLECTED   
    EG_GOAL_KILLED

This is an example of usage.

local sprite = getSprite(self);
if sprite:get("touched") ~= 1 then
	local image =  sprite.imageNo + 1
	if (image < sprite:frameCount()) then
		sprite:unMap();
		sprite:setImage(image);
		sprite:map();
	end
	if (image + 1) == sprite:frameCount() then
		sprite:unmarkAsGoal();	
		addToScore( 10 )
		callGameEvent(EG_GOAL_KILLED);
	end
	sprite:set("touched",1);
end

callLvEvent

  • in int event
  • out void
Call a level event. Valid values are the following.

EL_CREATE
EL_DRAW 
EL_RESTART
EL_GOAL_COLLECTED
EL_LEVEL_COMPLETED
EL_TIMEOUT 		
EL_KEY_PRESSED
EL_KEY_UP 	
EL_GOAL_KILLED   
EL_HANDLER

Alias: callLevelEvent


callTrigger

  • in int key
  • out void
Call the trigger using the supplied key. For example, if the key is set to 1 then all sprites that have trigger of 1 will be affected by this call.

clearDisplay

  • in void
  • out void
Remove all the visual displays on screen. This includes the score, timeLeft, health and debug, etc.

clearDisplay();

clearKeys

  • in void
  • out void
Clear the states for all the keys. This essentially clears the keyboard state.

copySprite

  • in Sprite src
  • out Sprite newSprite
Take the source sprite and create a new copy. Return an instance of the Sprite wrapper object.

CAUTION: using this function inside an handler such as OnSpawn can cause an infinite loop which will crash the engine.


counter_add

  • in string name
  • in int variance
  • out int new_value
Add a value of the designated counter.

counter_add("coins", 1);

Alias: counters_add


counter_dec

  • in string name
  • out int new_counter_value
Decrement the designated counter by 1.

Alias: counters_dec


counter_get

  • in string name
  • out int
Return the value of a counter.

Alias: counters_get


counter_inc

  • in string name
  • out int new_counter_value
Increase the designated counter by 1.

Alias: counters_inc


counter_set

  • in string name
  • in int value
  • out void
Set the value of a counter

Alias: counters_set


countGoals

  • in void
  • out int
debug("++goals: " .. countGoals());

debug

  • in string
  • out void
send a text string to the debug console.

debugClear

  • in void
  • out void
clear the debug log

decTimeLeft

  • in void
  • out void
Decrease the time left by one second.

if mtime >= getNextSecond() then
    setNextSecond( mtime + 1000 );
    if (not paused and getTimeLeft() > 0) then
        decTimeLeft();
        if getTimeLeft() == 0 and closureEvent == EVENT_NO_EVENT then
            callLvEvent( EL_TIMEOUT );
            setClosure( EVENT_TIMEOUT );
        end
    end
end

display_enableShadows

  • in int displayId
  • in bool shadow
  • out void
enable shadows under a display. work with text-only displays.

example

local id = addDisplayC("goalCount", 258, 0, DISPLAY_MESSAGE);
displaySetText(id, "XX");
displaySetVisible ( id, true );
displayEnableShadows( id, true );

Alias: displayEnableShadows


display_move

  • in int displayId
  • in int x
  • in int y
  • out void
change the position of a given display. x and y are absolute position given in pixels.

example

local id = addDisplayC( "playerIcon", 60, 60, DISPLAY_IMAGE);
displaySetXY(id, 0, 128);
displaySetImage ( id, OBJECT_PLAYERS   ,  4 );
displaySetVisible ( id, true );

Alias: displaySetXY


display_new

  • in string name
  • in int x
  • in int y
  • in int type
  • out int
create a new display elements using ``name``, x, y, and type.

you can use any of the DISPLAY_XXXX constants for ``type``.

DISPLAY_TIME_LEFT
DISPLAY_MESSAGE
DISPLAY_SCORE
DISPLAY_LIVES 
DISPLAY_HP

after adding a new display also remember to set it visible using the displaySetVisible function.

-- create a display of an image 
-- using the frame set 'ANNIE.OBL'
-- 0 is first image 
 
local id = addDisplayC( "petImage", 60, 60, DISPLAY_IMAGE);
displaySetImage ( id, IMAGES_ANNIE_OBL  , 0 );
displaySetVisible ( id, true );

see addDisplay for more sample usages.

Alias: addDisplayC


display_remove

  • in int displayId
  • out void
Remove a given display based on it's ID. Warning this may affect the ID of other displays.

Alias: removeDisplayById


display_setAlpha

  • in int displayId
  • in int alpha
  • out void

Alias: displaySetAlpha


display_setColor

  • in int displayId
  • in int red
  • in int green
  • in int blue
  • in int alpha
  • out void

Alias: displaySetColor


display_setExpireTime

  • in int displayId
  • in int time
  • out void

Alias: displaySetExpireTime


display_setFlagXY

  • in int displayID
  • in int flagX
  • in int flagY
  • out void
Change the flags that determine how this display is aligned.

FLAG_X_NONE         = 0;
    FLAG_X_ALIGN_LEFT   = 1;
    FLAG_X_ALIGN_RIGHT  = 2;
    FLAG_X_ALIGN_CENTER = 3; 
 
    FLAG_Y_NONE         = 0;
    FLAG_Y_ALIGN_TOP    = 1;
    FLAG_Y_ALIGN_BOTTOM = 2;
    FLAG_Y_ALIGN_CENTER = 3;

display_setFont

  • in int displayID
  • in int fontID
  • out void
Change the font assigned to paint a specific Display.

display_setFontSize

  • in int displayId
  • in int pxSize
  • out void
Change the pixel size of the text inside a display. This applies to text display only. See example below.

local id = addDisplayC("goalCount", 258, 0, DISPLAY_MESSAGE);
displaySetText(id, "XX");
displaySetVisible ( id, true );
displayEnableShadows( id, true );
displaySetShadowOffset(id, 2, 2);
displaySetFontSize(id, 14);

Alias: displaySetFontSize


display_setImage

  • in int displayId
  • in int imageSet
  • in int imageNo
  • out void
Assign an image to a display designated by displayId.

imageSet is set from the gameDB. Use the IMAGES_XXXX constants. imageNo are zero based index (from the first image, #0).

Note that each display can only accomodate one thing. If you assign an image to display that originally contained text. That text will be gone.

Alias: displaySetImage


display_setShadowColor

  • in int displayId
  • in int red
  • in int green
  • in int blue
  • in int alpha
  • out void
changes the color of the shadow cast by a display. works only with text displays where the shadow is enabled.

local id = addDisplayC("lives", 188, 0, DISPLAY_LIVES);
displaySetVisible ( id, true );
displayEnableShadows( id, true );
displaySetShadowOffset(id, 2,2);
displaySetShadowColor(id, 200, 200, 240, 128);

Alias: displaySetShadowColor


display_setShadowOffset

  • in int displayId
  • in int tx
  • in int ty
  • out void
change the offset of the shadow from the text. this works soley for text-only displays.

local id = addDisplayC("lives", 188, 0, DISPLAY_LIVES);
displaySetVisible ( id, true );
displayEnableShadows( id, true );
displaySetShadowOffset(id, 2,2);

Alias: displaySetShadowOffset


display_setTemplate

  • in int displayID
  • in string template
  • out void
Set the template for a given Display.

Example of templates. These follow the sprintf format. See C++ documentation for details.

"%.3d"
"%.8d"
"%.2d"

display_setText

  • in int displayId
  • in string text
  • out void
change the text displayed inside a text display.

example

local id = findDisplay("goalCount");
-- local goals = sprintf( "%.2d", countGoals() );
local goals = sprintf("%.2d", getGoalLeft());
displaySetText( id, goals ) ;

Alias: displaySetText


display_setType

  • in int displayId
  • in int type
  • out void
Change the type of given display. You provide the displayIID and a type from the following constants.

DISPLAY_TIME_LEFT
DISPLAY_MESSAGE 
DISPLAY_SCORE     
DISPLAY_LIVES  
DISPLAY_HP   
DISPLAY_DEBUG
DISPLAY_IMAGE

Alias: displaySetType


display_setVisible

  • in int displayId
  • in bool visible
  • out void

Alias: displaySetVisible


display_sizeText

  • in int displayId
  • in string text*
  • out int size
Returns the size of the string if not empty otherwise return the size of the text contained in the display.

in parameter text : optional and can be omitted.


element_move

  • in int layerId
  • in int elementId
  • in int aim
  • out bool
This function moves this element to a given aim. Valid values for aim are the following

UP
DOWN
LEFT
RIGHT

return true if succesful


element_moveBy

  • in int layerId
  • in int elementId
  • in int tx
  • in int ty
  • out bool

element_moveTo

  • in int layerId
  • in int elementId
  • in int x
  • in int y
  • out bool

element_new

  • in int layerId
  • in int imageSet
  • in int imageNo
  • in int x
  • in int y
  • in bool show*
  • out int elementId
This function is used to add an element to a background or foreground layer. If you want to add a sprite to the main the layer use the appropriate sprite function.

in parameter show : optional and can be omitted.

Alias: addElement


element_setImage

  • in int layerId
  • in int elementId
  • in int imageSet
  • in int imageNo
  • out bool
Change the image associated with a layer element.

local id = findDisplay("goalIcon");
if id ~= -1 then
   displaySetImage ( id, IMAGES_DIAMOND_OBL ,  0 );
   displaySetVisible ( id, true );
end

element_setVisible

  • in int layerId
  • in int elementId
  • in bool show
  • out void
Set a given element to hidden or shown. If show is true the object is set to visible otherwise, it is hidden.

findDisplay

  • in string name
  • out int displayId
findDisplay returns a displayId for an existing display.

These can be system display or an a user defined one. (see example)

example:

-- find a previously created display
-- and update it 
 
local id = findDisplay("goalCount");
local goals = sprintf( "%.2d", countGoals() );
displaySetText( id, goals ) ;

findLayer

  • in String name
  • out int layerId
return the layerId matching name or -1 if not found.

Debug:printf("layer fw is :%d", getLayerC ( "fw"));

Alias: getLayerC


findSprite

  • in int class
  • in int origin*
  • out int objId
Find the first sprite from origin which match the given class. Origin can be omitted, in which, it is assumed to be index 0.

Returns the objId if a match is found or otherwise -1.

local id = findSprte( CLASS_PLAYER_OBJECT );

in parameter origin : optional and can be omitted.


frameSet_getSize

  • in int frameSet
  • out int size
Get the number of images inside a frameset.

getBkColor

  • in void
  • out int red
  • out int green
  • out int blue
returns three integer values for each individual components such as red, green and blue of the current level's background color. This is just an alias for getBkColorC()

local bkColor = getBkColor();
Debug:printf("red: %u; green: %u; blue: %u", bkColor.red, bkColor.green, bkColor.blue);

Alias: getBkColorC


getBkColorC

  • in void
  • out int red
  • out int green
  • out int blue
Get the background color for the current level. Return the color as individual components as shown in the out list.

local red;
local green;
local blue;
red, green, blue = getBkColorC(); 
 
Debug:printf("red: %u; green: %u; blue: %u", red, green, blue);

getClosureEvent

  • in void
  • out int

getClosureTime

  • in void
  • out int

getDisplayById

  • in int displayId
  • out Display

getDisplayByName

  • in string displayName
  • out Display
Create a lua Display object matching the engine display of the provided name.

getExtra

  • in int objId
  • out Extra
see getExtraC()

getGoalLeft

  • in void
  • out int goalLeft
Return the number of items marked as a goals on the left. This uses a precompiled value. In contrast, countGoals() will do make a new count.

example:

local id = findDisplay("goalCount");
-- countGoals requires more computation
-- local goals = sprintf( "%.2d", countGoals() );
local goals = sprintf("%.2d", getGoalLeft());
displaySetText( id, goals ) ;

getHitTest

  • in int objId
  • in int aim
  • out HitTest
Takes an objId and returns a HitTest object.

see getHitTestC() for detais and HitTest class for details.


getHP

  • in void
  • out int player hp
Get the player's Hit Point count.

example:

setHP(500);
Debug:printf("hp:  %d", getHP());

getImage

  • in int objId
  • out int imageSet
  • out int ImageNo
Return the imageSet and imageNo for a given sprite

local imageSet;
local imageNo;
imageSet, imageNo = getImage(selt);

getImageSize

  • in int imageSet
  • in int imageNo
  • out int length
  • out int height
Returns the image length and height in pixels for an image designated by the imageSet / imageNo pair.

local s = getSprite(self);
local sx, sy = getImageSize(s.imageSet, s.imageNo);
if s.y + sy >= BUFFERHEI then
  s:setState(STATE_DEAD);
  s:hide();
end

getLastKey

  • in void
  • out int keyCode
Get the last key pressed. Use this in keyUP and keyPressed events to know which key was pressed.

-- this would be called inside the keyPressed 
-- or keyUp handler 
 
local keyCode = getLastKey();
if keyCode == KEY_SPACE then
   setBkColor(rand(), rand(), rand());
else
   Debug:printf("last key: %d", keyCode);
end

getLayer

  • in string name
  • out Layer
Returns the layer object matching the name provided. Use this function for background or foreground layer. This will not work with the main layer.

local layer = getLayer( "fw");
local element = layer:addElement(IMAGES_WHITEBALL_PNG, 0, 100, 100, true);

getLevelGoal

  • in void
  • out int levelGoal
The goal can be any of following values. (please note that they cannot be combined)

GOAL_ONLY               
GOAL_UP                
GOAL_DOWN         
GOAL_LEFT            
GOAL_RIGHT         
GOAL_NO_COMPLETE

GOAL_ONLY: when all goal marked objects are collected (removed)

GOAL_UP: when all goal marked objects are collected and player reaches the top of level (LODERUNNER)

GOAL_DOWN: when all goal marked objects are collected and player reaches the bottom of level.

GOAL_LEFT: when all goal marked objects are collected and player reaches the most left position.

GOAL_DOWN: when all goal marked objects are collected and player reaches the most right position .

GOAL_NO_COMPLETE : this requires that the level be declared completed via EndLevel function as to automatic completion is checked.

Debug:printf("level goal: %d", getLevelGoal());

getLookUp

  • in void
  • out bool
this function returns true if lookup is enabled. otherwise it returns false.

getPlayer

  • in void
  • out Sprite
Get a Sprite object that contains the information about the player. Returns a wrapper with the desired data.

local player = getPlayer();
Debug:printf("player id= %d; name: %s", player.id, player.name);

getPlayerID

  • in void
  • out int objId
returns the objId of the player.

local id = getPlayerC();
Debug:printf("player_id: %x", id);

Alias: getPlayerC


getProto

  • in int objType
  • out Proto
Get the information about a given objType. Return a Proto object containing the data requested.

getScore

  • in void
  • out int current score
Returns the player' score.

debug( "score:" .. getScore());

getScreenSize

  • in void
  • out int len
  • out int hei
Returns a tuple containing the screen size (opengl context).

local len
local hei
len, hei = getScreenSize()

getSkill

  • in void
  • out int skill
Get the skill level for the current game.

The value retuned is one of the following.

SKILL_NORMAL	    
SKILL_NIGHTMARE	    
SKILL_HELL	
SKILL_INSANE

example

if getSkill() == SKILL_NORMAL then
  debug("=>normal difficulty");
  setTickScale(1000 / 80);
  addToHP(50);
end

getSprite

  • in int objId
  • out Sprite
similar to getSpriteVars except that it will return the data inside as an object for easier management.

one thing to remember though is that modify individual fields of ``sprite`` will not alter the sprite. only your copy.

to make changes, you must call base methods such as s:setAim(). see example

local s = getSprite(self); 
 
  debug("this is my detail:");
  debug("x = " .. s.x);
  debug("y = " .. s.y); 
 
  local aim = s.aim; 
 
  s:unMap(); 
 
  if s:canFall () then
    s:move( DOWN )  ;
  else
    if ticks % 5 == 0 then    
 
      if s:isPlayerThere(aim) then
	  s:attackPlayer();
      end 
 
      if aim < LEFT or aim > RIGHT then
	aim = LEFT
      end 
 
      if s:canMove(aim) then
	s:move(aim);
	if s:canFall() then
	  aim = XOR(aim, 1);
	  s:move(aim);
	end 
      else
	  aim = XOR( aim, 1);      
      end 
 
      s:setAim ( aim ); 
 
    end 
  end 
 
  s:map();

getTicks

  • in void
  • out int ticks
ticks are the internal unit for relative speed comparison within the engine.

the number of ticks per seconds is directly related to the tick scale.

the best way to deal with ticks is time splicing

example

local ticks = getTicks();
if ticks % 5 == 0 then
  -- this will be executed 20% of the time
  -- or 1 in every 5 cycles
end

getTickScale

  • in void
  • out int tickScale
The tickScale is the number of times per second that the engine main loop is executed. see setTickScale for details

getTime

  • in void
  • out int time elapsed
Returns the time elapsed in miliseconds since the engine was started. Depening on the content this could be the level or the whole game.

1000 = 1 second in real time

Debug:printf("%d", getTime() );

getVersion

  • in void
  • out int lgck_version
This function returns the version of lgck currently powering up the game engine.

Debug:printf("version: %8.8x", getVersion());

getWrapFlag

  • in void
  • out int wrapFlag
Returns the wrap arround state for the current level.

Valid values are a combination of the following.

WRAP_UP                 
WRAP_DOWN          
WRAP_LEFT             
WRAP_RIGHT

local wrapFlag = getWrapFlag();
Debug:printf("wrapFlag: %d", wrapFlag);

You can test for individual directions using the binary AND operator.

AND (wrapFlag, WRAP_UP)

hasGravity

  • in void
  • out bool gravity
return true if gravity is enabled on this level.

if (hasGravity()) then 
   debug("this level has gravity");
else
   debug("this level doesn't have gravity"); 
end

hasItem

  • in int objType
  • out bool result
Return true if the objType is part of the player's inventory.

killPlayer

  • in void
  • out void
Just kills the player. Triggers the same events as any occurence where this would happen.

killPlayer()

layer_clear

  • in int layerId
  • out bool result
Clear the layer designed by layer id. This function will return true if succesful.

local id = getLayerC("fw");
if layer_clear( id ) then
  Debug:printf("layer was cleared");
end

layer_delete

  • in int layerOD
  • out void
Delete a layer by id. This may invalidate the other layer ids.

layer_getElement

  • in int layerId
  • in int elementId
  • out int imageSet
  • out int ImageNo
  • out int x
  • out int y
  • out bool show

layer_getOffsetX

  • in int layerID
  • out int x
Get X-offset of a layer.

layer_getOffsetY

  • in int layerID
  • out int y
Get the Y-offset of a layer.

layer_getSize

  • in int layerId
  • out int size
This function returns the object/sprite count on the layer identified by layerId. You can get the layerId with getLayerC().

local id = getLayerC ( "fw");
Debug:printf("layer size: %d", layer_getSize( id ));

layer_new

  • in String name
  • in int type
  • in int hSpeed*
  • in int vSpeed*
  • out int layerId
valid types

LAYER_BK             
    LAYER_FW

valid speeds

SPEED_NOSCROLL,
        SPEED_WHOLE,
        SPEED_1_2,
        SPEED_1_4,
        SPEED_1_8,
        SPEED_1_16,
        SPEED_1_32

in parameter hSpeed : optional and can be omitted.

in parameter vSpeed : optional and can be omitted.

Alias: addLayerC


layer_setOffsetX

  • in int layerID
  • in int x
  • out void
Set layer top corner x-offset.

layer_setOffsetY

  • in int layerID
  • in int y
  • out void
Set the layer y-offset.This is set relative to the top corner.

layer_setSpeed

  • in int layerID
  • in int hSpeed
  • in int vSpeed
  • out void
Set the layer scroll speed.

loadGame

  • in string filename
  • out void
EXPERIMENTAL. Load a save game. Don't call from a sprite handler since this will lead to undefined behavior.

MAX

  • in int value1
  • in int value2
  • out int
return the largest of the two integers being passed to it.

MIN

  • in int value1
  • in int value2
  • out int
Returns the smallest value of the two integers.

nextTick

  • in void
  • out void

openStream

  • in string soundFile
  • out bool
Open a sound file for streaming. If the soundFile was opened succesfully, this function will return true. Your next step is to call playStream() to play the file.

openStream("level01.ogg");

OR

  • in int a
  • in int b
  • out int binary or (a , b)

pause

  • in void
  • out void
pause the game. equivalent to pressing F4

playSound

  • in string sound...
  • out void
Loads a sound resource from the current lgckdb database and plays it. The name of the sound is case sensitive so please be sure to have exact same spelling.

This function can accept multiple inputs.

playSound("OUCH");
  playSound("OUCH", "JUMP");

playStream

  • in void
  • out void
Play an opened stream. You must first use openStream() to ready the stream to be played.

proto_get

  • in int objType
  • out array proto
Get the proto information for a given objType. Returns an array with the data requested.

Alias: getProtoC


rand

  • in void
  • out int
returns a random value.

remap

  • in void
  • out void
Clear the collisionMap and recreate it from scratch. Very expensive in execution cycles.

removeDisplayByName

  • in string name
  • out void
Remove the display that matches the given name.

removeFromInventory

  • in int objType
  • out void

resetInventory

  • in void
  • out void

saveGame

  • in string filename
  • out void
EXPERIMENTAL. Create a save game. Don't call from a sprite handler since this will lead to undefined behavior.

scene_getSize

  • in void
  • out int spriteCount
returns the number of sprites in the mainLayer.

Alias: getSpriteCount


setBkColor

  • in int red
  • in int green
  • in int blue
  • out void
Set the background color for the current level from the red, green and blue components of the provided as three integer values (max 255, 255, 255 is pure white). This is just an alias for the now depreciated setBkColorC function.

setBkColor(128, 40, 64);

Alias: setBkColorC


setBkColorC

  • in int red
  • in int green
  • in int blue
  • out void
Set the background color for a given level.

-- set the background color at random
setBkColorC(rand() % 256, rand() % 256, rand() % 256);

setBorderColor

  • in int red
  • in int green
  • in int blue
  • out void
set border color.

setBorderColor(rand(),rand(),rand());

setEndLevel

  • in void
  • out void
Close the current level. This should take the player to the next level.

setHP

  • in int hitPoints
  • out int the player's new hp count
Set the player's Hit Point count;

example:

setHP(500);
Debug:printf("hp:  %d", getHP());

setKey

  • in int keyCode
  • in bool set
  • out void
If set is true this key is considered pressed otherwise it is considered not pressed.

setLevelGoal

  • in int goal
  • out void
The goal can be any of following values. (please note that they cannot be combined)

GOAL_ONLY               
GOAL_UP                
GOAL_DOWN         
GOAL_LEFT            
GOAL_RIGHT         
GOAL_NO_COMPLETE

GOAL_ONLY: when all goal marked objects are collected

GOAL_UP: when all goal marked objects are collected and player reaches the top of level (LODERUNNER)

GOAL_DOWN: when all goal marked objects are collected and player reaches the bottom of level.

GOAL_LEFT: when all goal marked objects are collected and player reaches the most left position.

GOAL_DOWN: when all goal marked objects are collected and player reaches the most right position .

GOAL_NO_COMPLETE : this requires that the level be declared completed via EndLevel function as to automatic completion is checked.

-- prevent this level from being completed automatically
setLevelGoal(GOAL_NO_COMPLETE);

setLookup

  • in bool lookup
  • out void
Enables or disables lookup.

setNextSecond

  • in int mtime
  • out void
Set the next second during a countdown. This is called by the default game handler.

-- test for timeout
        if mtime >= getNextSecond() then
            setNextSecond( mtime + 1000 );
            if (not paused and getTimeLeft() > 0) then
                decTimeLeft();
                if getTimeLeft() == 0 and closureEvent == EVENT_NO_EVENT then
                    callLvEvent( EL_TIMEOUT );
                    setClosure( EVENT_TIMEOUT );
                end
            end
        end

setSpeed

  • in int speed
  • out void
Set the game speed. The default value is 90. The maximum value is 200.

The speed is calculated as follow. 1000 / speed = number of cycles per second.

Each cycle is a tick. This is the base unit for everything in the game itself.

Also setTickScale()


setTickScale

  • in int tickScale
  • out void
Change the level tick scale. This makes the game go faster or slower.

Tick scale is calculate : 1000 / TickRate

TickRate is the number of times per second that the main loop is executed.

See example:

-- in this example the tick rate is 95
-- which is very fast !!! 
 
if SKILL == SKILL_INSANE then
  debug("=>insane difficulty");
  setTickScale(1000 / 95);
  addToHP(-20);
end

setWrapFlag

  • in int wrapFlag
  • out void
This function modifies the behavior defined for the level.

Wrap allows object to move from one edge of the map to the other.

A popular example of this is the classic PACMAN.

wrapFlag can be a combination of the following value.

WRAP_UP             
WRAP_DOWN      
WRAP_LEFT         
WRAP_RIGHT

-- allow wrapping only at the the top of the screen
setWrapFlag( WRAP_UP );
-- check the flag to see that change was made
local wrapFlag = getWrapFlag();
Debug:printf("A wrapFlag: %d", wrapFlag);

SHL

  • in int value
  • in int bits
  • out int
Shift left by x bits.

showConsole

  • in bool show
  • out void
examples

showConsole ( true )
showConsole ( false )

SHR

  • in int value
  • in int bits
  • out int
Shift right by x bits.

snapshot_clear

  • in void
  • out void
EXPERIMENTAL: Clear the previous saved snapshot of the current level.

snapshot_reload

  • in void
  • out bool
EXPERIMENTAL: Reload an existing snapshot of the current level. This will restore the level to the state where the snapshot was taken,

snapshot_take

  • in void
  • out void
EXPERIMENTAL: Take a snapshot of the current level. (see snapshot_reload)

sprintf

  • in string format
  • out string
This function formats a text string. Works exactly like it's C counterpart.

local s = sprintf("My name is %s", "Frank");
-- print the result to the debug console
Debug:printf(s); 
 
local s = sprintf("1 + 1 = %d", 2);
-- print the result to the debug console
Debug:printf(s);

sprite_activate

  • in int objId
  • out void
Activate this sprite. Inactive sprite do not consume their handlers until they are activated. Activation can be automatic or manual via scripting using this function.

activateSprite(self)

Alias: activateSprite


sprite_addItem

  • in int objId
  • in int protoId
  • in int count
  • out void

sprite_attackPlayer

  • in int objId
  • out void

Alias: attackPlayer


sprite_callEvent

  • in int objId
  • in int event
  • out void
Call an event handler. ObjId is the sprite to receive the event as you can see in the example below.

local id = getPlayerC();
Debug:printf("player_id: %x", id);
callObjEvent(id, EO_DEATH);

Event can be any of the following constants.

EO_SPAWN   
    EO_ACTIVATE
    EO_DEATH	
    EO_HURT	    
    EO_TOUCH	
    EO_TRIGGER
    EO_HANDLER
    EO_SPLAT	
    EO_HIT_TEST
    EO_ZKEY	
    EO_AUTO	
    EO_JUMP
    EO_FALL	
    EO_LAND	
    EO_LEAP	
    EO_MOVE	
    EO_FIRE

Alias: callObjEvent


sprite_canFall

  • in int objId
  • out bool
return true if the object identified by objId can fall. This is reflected by the current rules on the level.

if (canFall ( self )) then
  debug ("I'm falling !!!");
end

Alias: canFall


sprite_canMove

  • in int objId
  • in int aim
  • out bool

Alias: canMove


sprite_changeTo

  • in int objId
  • in int objType
  • out void
Change the sprite to another object based on objType.

Alias: changeTo


sprite_childCount

  • in int spriteId
  • out int childCount
Count the number of children sprites. There are typically bullets.

sprite_clear

  • in int objId
  • out void
Clear a sprite and mark the entry for garbage collection.

Alias: clearSprite


sprite_copy

  • in int objId
  • out int newObjId
copy a sprite and create a new instance. This function returns the ObjId handle if succesful or -1 on failure.

CAUTION: using this function inside an handler such as OnSpawn can cause an infinite loop which will crash the engine.

Alias: copySpriteC


sprite_frameCount

  • in int objid
  • out int number_of_frames
Get the frame count for a given sprite. This is based on the current frameset associated with this sprite.

sprite_freeze

  • in int objId
  • out void
Set the freeze flag to on. This will cause the sprite to stop moving. Engine class and animation handlers will honor this flag.

It is your responsability to support this flag in custom handlers of your own making.

Alias: freezeSprite


sprite_get

  • in int objId
  • in mixed key
  • out int value
Get a sprite property. If the key is a string is it a user-defined property.

The key can also be a constant. The following values are predefined by the engine. The values from 0 to 1000 are considered reserved by the engine.

EXTRA_ORGPROTO
EXTRA_ORGX          
EXTRA_ORGY          
EXTRA_HP            
EXTRA_OLDAIM1     
EXTRA_OLDAIM2     
EXTRA_FALLHEIGHT  
EXTRA_LIVES       
EXTRA_ACTIVE      
EXTRA_BULLETCOUNT 
EXTRA_OWNER       
EXTRA_FLAGS       
EXTRA_PATHDIR     
EXTRA_PATHPTR     
EXTRA_ANIMSEQ     
EXTRA_ANIMPTR     
EXTRA_ANIMSPEED 
EXTRA_DEATHINDICATOR
EXTRA_AGE   
EXTRA_TIMEOUT     
EXTRA_TAGFLAGS 
EXTRA_INVENTORY

sprite_getClass

  • in int objId
  • out int classId
Return the class of a given object. The classId is one of the predefined constants CLASS_XXXXX.

Alias: getObjClass


sprite_getExtra

  • in int objId
  • out array
Returns an array containing the sprite's extra data.

You can access this information via the following indexes.

EXTRA_ORGPROTO
    EXTRA_ORGX
    EXTRA_ORGY
    EXTRA_HP
    EXTRA_OLDAIM1
    EXTRA_OLDAIM2
    EXTRA_FALLHEIGHT
    EXTRA_LIVES
    EXTRA_ACTIVE
    EXTRA_BULLETCOUNT
    EXTRA_OWNER
    EXTRA_FLAGS
    EXTRA_PATHDIR
    EXTRA_PATHPTR
    EXTRA_ANIMSEQ
    EXTRA_ANIMPTR
    EXTRA_ANIMSPEED
    EXTRA_DEATHINDICATOR

Alias: getExtraC


sprite_getHeight

  • in int sprite_id
  • out int height
Get the sprite heigth.

sprite_getHitTest

  • in int objId
  • in int aim
  • out array bk
  • out array fw
  • out array ac
  • out int flags
  • out bool player
Performs a hit test for a given object (sprite) and return the result. This raw data straight from the game engine. Of course if you are looking at this function it's because you are into writing ai and advances engine extension so you ought to expect a bit of complexity.

The objId is generally the "self" variable you would get from the object handler. Although, it could also be obtained with something else like findSprite().

Possible values for aim are UP, DOWN, LEFT, RIGHT and HERE, These values cannot be combined.

local bk, fw, ac, flags, player = getHitTestC( self,  UP  );

The results of this function can be a bit confusing. For starters, "flags" can be a combination of any of the following.

FLAG_NONE		   
    FLAG_METAL		   
    FLAG_NOSOUND       
    FLAG_WATER	
    FLAG_DEATH	
    FLAG_HIT		    
    FLAG_TELEPORT

bk is an array of classes.

fw is an array of classes and objId. There value are in pair starting at index 1.

ac is an array of classes and objId. There value are in pair starting at index 1.

for i=1, #fw, 2 do
  local class = fw[i] ;
  local objId = fw[i + 1];
  -- do something else ....   
end 
 
for i=1, #ac, 2 do
  local class = ac[i] ;
  local objId = ac[i + 1];
  -- do something else ....   
end

player is boolean that indicate whether or not the player is there.

Alias: getHitTestC


sprite_getHP

  • in int objId
  • out int hp
Get the sprite hit points count.

sprite_getName

  • in int objId
  • out string name
Returns a string containg the object name. (null terminated string, max 31 characters)

Debug:printf("player picked up a %s", getObjName(self));

Alias: getObjName


sprite_getObjType

  • in int objId
  • out int objType
Get the object type for a given object ( e.g. instance ).

these values can be corrolated with the OBJECT_XXXX constants defined by LGCK for your game.

example:

debug("type: " .. getObjType( self ));
debug("name:" .. getObjName( self ));

Alias: getObjType


sprite_getString

  • in int objId
  • out string
Get the custom hint/description associated with a given sprite.

sprite_getTriggerKey

  • in int objId
  • out int triggerKey

Alias: getTriggerKey


sprite_getUID

  • in int objId
  • out int uid
Returns extraData uid for a given sprite.

Alias: getExtraUID


sprite_getVars

  • in int objId
  • out int x
  • out int y
  • out int aim
  • out int objectType
  • out int imageSetId
  • out int imageNo
  • out int triggerFlag
  • out int stateFlag
  • out int actionMask
  • triggerFlag bit mask
01, 02, 04, 08, 10 TRIGGER_KEYS = 0x1f 20 TRIGGER_GOAL = 0x20 40 TRIGGER_FROZEN = 0x40 80 TRIGGER_HIDDEN = 0x80

to get the triggerKey out of triggerFlag use `AND (triggerFlag, TRIGGER_KEYS)`.

goal, frozen and hidden can be access using the TRIGGER_xxxx method above see common.lua for the definitions.

this is stuff for advanced users

  • stateFlag
use STATE_XXXX constants

local x;
local y;
local aim;
x , y, aim = getSpriteVars( self );

Alias: getSpriteVars


sprite_getWidth

  • in int sprite_id
  • out int width
Get the sprite width in pixels. This reflect the current frame being displayed by engine to represent this sprite.

sprite_hasItem

  • in int objId
  • in int protoId
  • out bool hasItem

sprite_hide

  • in int objId
  • out void
Set the hidden flag on this sprite. This will cause the engine to not display this given sprite/object. All system based classes will also ignore this sprite until it becomes visible again.

Alias: hideSprite


sprite_isActive

  • in int objId
  • out bool active
Return the active state of a given sprite. (bool: true, false)

sprite_isDead

  • in int objId
  • out bool
returns true if the sprite is dead.

if isDead(self) then
   Debug:printf("This sprite is dead");
end

Alias: isDead


sprite_isFrozen

  • in int objId
  • out bool frozen
returns true if the sprite is frozen.

sprite_isGoal

  • in int objId
  • out bool goal
returns true if the sprite is marked as a goal.

sprite_isHidden

  • in int objId
  • out bool
Return true if this object is hidden. Please note that this doesn't apply to system invisible objects which are not considered hidden in the strict sense of the word here.

Alias: isHidden


sprite_isMonster

  • in int objId
  • out bool
returns true if the object is a monster.

Alias: isMonster


sprite_isPlayer

  • in int objId
  • out bool
Tests if the sprite is a player object. Returns true if sprite is of player class.

sprite_isPlayerThere

  • in int objId
  • in int aim
  • out bool

Alias: isPlayerThere


sprite_isVisible

  • in int objId
  • out bool
Checks if the sprite is visible. Visibility is the combination of two things:

  • Is the sprite on screen?
  • Is the sprite hidden?

You can check if the sprite is hidden with sprite_isHidden.

Alias: isVisible


sprite_kill

  • in int objId
  • out void
Don't try this inside the sprite's own event handler!!! Don't use this on a player object. Use killPlayer() or player:setState( STATE_DEAD ) instead as this will not have the desired effect.

Alias: killSprite


sprite_land

  • in int objId
  • out void
The land() method is called by the engine whenever a sprite has landed (following a fall). The usefulness of this method is debatable at runtime. However, it is made available should be it prove useful in custom handlers/ai where this functionality might have a purpose. (e.g. if you are creating a custom monster whereas the engine will not handle these details for you)

Alias: land


sprite_map

  • in int objId
  • out void

Alias: mapSprite


sprite_markAsGoal

  • in int objId
  • out void
Set the sprite to be a goal for the level to be completed.

Alias: markSpriteAsGoal


sprite_move

  • in int objId
  • in int aim
  • in int objId
  • in int tx
  • in int ty
  • out void
aim is one of the UP, DOWN, LEFT and RIGHT constants

you generally check to see of the object can move in a given direction using canMove()

this second version also allows you to control the translation from current position. if you want defined where to position it then use moveSpriteTo().

Alias: moveSprite


sprite_moveBy

  • in int objId
  • in int tx
  • in int tx
  • out void
you generally check to see of the object can move in a given direction using canMove()

this allows you to control the translation from current position. if you want defined where to position it then use moveSpriteTo().

Alias: moveSpriteBy


sprite_moveTo

  • in int objId
  • in int x
  • in int y
  • out void
note: prior to moving, animating, killing or deleting a sprite you should first use unMapSprite(). if you wish to still use it you will also need to use mapSprite after the transformation.

Please ensure that x and y coordonates are multiples of 8 and within the game world. You can do that with the bitwise operator AND (x, 0xfff8).

Alias: moveSpriteTo


sprite_new

  • in int x
  • in int y
  • in int aim
  • in int objectType
  • in int imageSet*
  • in int imageNo*
  • out int objId
although it might not make any real difference but performance wise addSpriteC is probably faster that addSprite (if you don't need the extra overhead).

in parameter imageSet : optional and can be omitted.

in parameter imageNo : optional and can be omitted.

Alias: addSpriteC


sprite_removeItem

  • in int objId
  • in int protoId
  • out void

sprite_resetInventory

  • in int objId
  • out void

sprite_set

  • in int objId
  • in mixed key
  • in int value
  • out void
Set a sprite property. If the key is a string is it a user-defined property.

The key can also be a constant. The following values are predefined by the engine. The values from 0 to 1000 are considered reserved by the engine.

EXTRA_ORGPROTO
EXTRA_ORGX          
EXTRA_ORGY          
EXTRA_HP            
EXTRA_OLDAIM1     
EXTRA_OLDAIM2     
EXTRA_FALLHEIGHT  
EXTRA_LIVES       
EXTRA_ACTIVE      
EXTRA_BULLETCOUNT 
EXTRA_OWNER       
EXTRA_FLAGS       
EXTRA_PATHDIR     
EXTRA_PATHPTR     
EXTRA_ANIMSEQ     
EXTRA_ANIMPTR     
EXTRA_ANIMSPEED 
EXTRA_DEATHINDICATOR
EXTRA_AGE   
EXTRA_TIMEOUT     
EXTRA_TAGFLAGS 
EXTRA_INVENTORY

sprite_setAim

  • in int objId
  • in int aim
  • out void

Alias: setAim


sprite_setHP

  • in int objID
  • in int hp
  • out void
Set the hit points for this sprite.

sprite_setImage

  • in int objId
  • in int imageSet
  • in int imageNo
  • out void
Change the image for a given sprite.

The example below shows the best practice. Alternative methods include tryAnimation().

local imageSet;
local imageNo;
imageSet, imageNo = getImage(selt);
setImage(self, imageSet, XOR(imageNo, 1));

Alias: setImage


sprite_setOwner

  • in int objId
  • in int ownerid
  • out void
Set the owner of this sprite. This set the relationship between a sprite and a bullet for example.

sprite_setState

  • in int objId
  • in int stateFlag
  • in bool flip
  • out int stateFlag
Change the state flags for a given sprite.

if flip is true the bits are set on otherwise they are cleared.

State flag is a combination of the following:

STATE_FALL		
    STATE_DEAD	
    STATE_HIT		    
    STATE_JUMP	
    STATE_BEGINNING    
    STATE_FIRING       
    STATE_LOOKUP

returns the newly modified stateFlag.

Alias: setState


sprite_setTriggerKey

  • in int objId
  • in int key
  • out void
changes the trigger key of a given obj. if set to zero, this will clear the trigger key entirely. values will be binary AND with 0x1f to ensure they are within limit. Valid trigger keys are between 1 and 31.

Alias: setTriggerKey


sprite_show

  • in int objId
  • out void
show the current sprite. This reverses the hideSprite() function. If the sprite is already visible this will not have any effect on it.

Alias: showSprite


sprite_spawn

  • in int objId
  • out void
Spawn is called upon during the creation of a new sprite to initialize the member variables. It's usefulness at runtime is debatable. However, it is available should there be a need for it.

Alias: spawn


sprite_stopAnimation

  • in int objId
  • out void
Stop the current animation sequence. This is also breaks repeating animations.

stopAnimation(self);

Alias: stopAnimation


sprite_testFlags

  • in int objId
  • in int mask
  • out bool true if bitwise matched
note: currently this function only works with the player object flags are outlined as const FLAG_xxxxx

you must supply both args or the function will return false and spit out a warning on the debug console

local sound = "";
  if not testFlags(self,  FLAG_NOSOUND)  then
    if  testFlags(self , FLAG_METAL)   then
	  sound = "METAL";
    else
      if ticks % 12 == 0 then
	  sound = "WALK2";
      else
	  sound = "WALK";
      end
    end
    playSound( sound );
  end

The mask can be a combination of any of the following. Although, generally speaking you want to include only one.

FLAG_NONE		   
    FLAG_METAL		   
    FLAG_NOSOUND       
    FLAG_WATER	
    FLAG_DEATH	
    FLAG_HIT		    
    FLAG_TELEPORT

Alias: testFlags


sprite_togglePathPlayback

  • in int objId
  • in bool enable
  • out void
Toggle playback of custom path. Path playback allows a custom path that is assigned to a sprite to be played used to remotely control this sprite. If enabled, the custom path is utilized. Otherwise, it is ignored.

sprite_triggerHitState

  • in int objId
  • out void
Trigger the hit state for a given object. This is usually called when the object is "hurt".

ObjId is the sprite id.

No return value.

Alias: triggerHitState


sprite_tryAnimation

  • in int objId
  • in int animSeq
  • out bool
This plays a designated animation sequence for a given objectId. If you are using this function inside an event handle, the objectId is often the `self` variable which points to the object being handled.

The animation sequence is one of the following values. In order to use this animation, the target object must have corresponding images attached to it.

AS_DEFAULT 
AS_IDLE       
AS_CUSTOM1    
AS_CUSTOM2    
AS_STAND        
AS_STAND_UP
AS_STAND_DOWN  
AS_STAND_LEFT  
AS_STAND_RIGHT  
AS_MOVE       
AS_MOVE_UP     
AS_MOVE_DOWN    
AS_MOVE_LEFT    
AS_MOVE_RIGHT  
AS_JUMP         
AS_JUMP_UP 
AS_JUMP_DOWN  
AS_JUMP_LEFT   
AS_JUMP_RIGHT  
AS_HURT        
AS_HURT_UP      
AS_HURT_DOWN 
AS_HURT_LEFT    
AS_HURT_RIGHT 
AS_ATTACK      
AS_ATTACK_UP    
AS_ATTACK_DOWN  
AS_ATTACK_LEFT 
AS_ATTACK_RIGHT 
AS_RUN          
AS_RUN_UP     
AS_RUN_DOWN    
AS_RUN_LEFT     
AS_RUN_RIGHT   
AS_DEAD        
AS_DEAD_UP      
AS_DEAD_DOWN    
AS_DEAD_LEFT   
AS_DEAD_RIGHT

This function returns true if succesful or false if the animSeq value is out of bound or the object has no animation sequence defined which match the animSeq value.

if tryAnimation(self,  AS_DEAD_UP) then
   debug("animation worked!!! :D");
end

Alias: tryAnimation


sprite_tryPath

  • in int objId
  • in int pathDir
  • in int aim*
  • out bool
Have the designated object try a path. The pathDir can be any of the following constants.

PS_DEFAULT     
        PS_IDLE        
        PS_CUSTOM1      
        PS_CUSTOM2    
        PS_ATTACK      
        PS_ATTACK_UP 
        PS_ATTACK_DOWN 
        PS_ATTACK_LEFT 
        PS_ATTACK_RIGHT
        PS_JUMP        
        PS_JUMP_UP
        PS_JUMP_DOWN    
        PS_JUMP_LEFT  
        PS_JUMP_RIGHT  
        PS_JUMP_UP_LEFT 
        PS_JUMP_UP_RIGHT
        PS_JUMP_DN_LEFT
        PS_JUMP_DN_RIGHT
        PS_MOVE       
        PS_MOVE_UP
        PS_MOVE_DOWN  
        PS_MOVE_LEFT  
        PS_MOVE_RIGHT  
        PS_MOVE_UP_LEFT
        PS_MOVE_UP_RIGHT
        PS_MOVE_DN_LEFT 
        PS_MOVE_DN_RIGHT

Aim can be either UP, DOWN, LEFT or RIGHT. If aim is not provided, INVALID is assumed.

Return true if the path defined. This function is similar to tryAnimation(). It only works with the player at the moment.

local id = getPlayerC();
Debug:printf("player_id: %x", id);
tryPath(id, PS_JUMP_LEFT);

in parameter aim : optional and can be omitted.

Alias: tryPath


sprite_unFreeze

  • in int objId
  • out void
Reverse the effect of freezeSprite. reactivative it.

another way of doing this is through the Sprite interface.

activateSprite(self); 
 
-- is equivalent to 
 
local sprite;
sprite = getSprite(self);
sprite:activate();

Alias: unFreezeSprite


sprite_unMap

  • in int objId...
  • out void
unMapSprite is required before making any changes to a sprite's position, visibility or attributes. not doing so will result in very nasty and hard to track bugs.

Alias: unMapSprite


ss_animate

  • in void
  • out void
internal. Used by the engine to animate all sprites.

ss_autoCenter

  • in void
  • out void
internal. Auto centers the screen on the player sprite.

ss_clear

  • in int red
  • in int green
  • in int blue
  • out void
Clear the screen with a given color. These rgb values are between 0 and 255.

ss_clearKeys

  • in void
  • out void
Internal. Clear keyboard map.

ss_doManage

  • in void
  • out void
internal. Used by the engine to manage all sprite interactions in the game context.

ss_drawText

  • in int x
  • in int y
  • in string text
  • in int fontid
  • in int fontSize
  • in int rgba
  • in int shadowOffset*
  • in int shadowColor*
  • out void
Draw text on the screen at x,y. Memory arrangement of the rgba color is 0xAABBGGRR. This function must be executed within the onDraw function otherwise it will have no effect.

ss_drawText(100, 50, "This is a test", 0, 20, 0xa0ee20cc, 2, 0xffffffff);

in parameter shadowOffset : optional and can be omitted.

in parameter shadowColor : optional and can be omitted.


ss_getNextTick

  • in void
  • out int
Returns time in milliseconds of the next engine tick.

ss_getPause

  • in void
  • out bool
This function returns true if the game is paused,

ss_manageAuto

  • in void
  • out void
internal

ss_manageKeyEvents

  • in void
  • out void
internal

ss_managePlayer

  • in void
  • out void
internal.

ss_manageTasks

  • in void
  • out void
internal

ss_notifyAll

  • in int gameEventOD
  • in int levelEventID
  • in int spriteEventID
  • in int spriteEventID
  • out void
Internal. Notify all sprite on the level that an event has occured. In the extended version events can be sent to both the level and the game.

ss_notifyClosure

  • in void
  • out void
SYTEM FUNCTION - Notfy all sprites that a closure event in eminent. This will repeate until the event is resolved.

calls onNotifyClosure() EO_NOTIFYCLOSURE

local closureEvent, closureTime = getClosure();
    local mtime = getTime();
    --if (closureEvent ~= EVENT_NO_EVENT and mtime >= closureTime) then
    if closureEvent ~= EVENT_NO_EVENT then
        if mtime >= closureTime then
            return closureEvent;
        else
            ss_notifyClosure();
        end
    end

ss_paint

  • in int x1
  • in int y1
  • in int x2
  • in int y2
  • in unsigned int rgba
  • in bool fill
  • out void
Internal. Draw a rectangle of a given color. If fill is set the rectangle is full otherwise it will be hollow. Memory arrangement of the rgba color is 0xAABBGGRR. This function must be executed within the onDraw function otherwise it will have no effect.

ss_paint(0,0,40,40, 0xaa00aa90, TRUE);

ss_paintImage

  • in int x
  • in int y
  • in int frameSet
  • in int frameNo
  • out void
Internal. Draw an image on screen at x,y.

ss_setNextTick

  • in int time
  • out void
Set the time in milliseconds for the next engine tick.

stopStream

  • in void
  • out void
Stop a playing sound/music stream

stopStream();

strv_del

  • in string key
  • out void
Delete global string.

strv_get

  • in string key
  • out string val
Get global string

strv_set

  • in string key
  • in string val
  • out void
Set global string

testJoyState

  • in int mask
  • out bool true if bitwise matched, otherwise false
note: currently this function only works with the player object

states are outlined as const JOY_xxxxx

if (ticks % 5 == 0) and testJoyState( JOY_FIRE ) then
    local x;
    local y;
    local aim;
  
    x , y, aim = getSpriteVars( self ); 
 
    if testJoyState( JOY_LEFT ) then 
      aim = LEFT;
      x = x - 8;
      y = y + 8;
    elseif testJoyState( JOY_RIGHT ) then
      aim = RIGHT;
      x = x + 32;
      y = y + 8;
    elseif testJoyState( JOY_UP ) then
      aim = UP;
      x = x + 8;
      y = y - 8;
    elseif testJoyState( JOY_DOWN ) then
      aim = DOWN;
      x = x + 8;
      y = y + 32;
    end  
 
    local bullet = addSprite (
      x, 
      y, 
      aim,					-- UP, DOWN, LEFT, RIGHT
    OBJECT_BULLET_LITTLE_STAR__PLY_		-- put the object type 
    ); 
 
    playSound("pow.ogg");
  end

testKey

  • in int keyCode
  • out bool
The keyCode can be any of the following values. This fucntion returns true if the key is pressed. Other values may have unpredictable results.

KEY_A
KEY_B
KEY_C
KEY_D
KEY_E
KEY_F
KEY_G
KEY_H
KEY_I
KEY_J
KEY_K
KEY_L
KEY_M
KEY_N
KEY_O
KEY_P
KEY_Q
KEY_R
KEY_S
KEY_T
KEY_U
KEY_V
KEY_W
KEY_X
KEY_Y
KEY_Z
KEY_0
KEY_1
KEY_2
KEY_3
KEY_4
KEY_5
KEY_6
KEY_7
KEY_8
KEY_9
KEY_F1
KEY_F2
KEY_F3
KEY_F4
KEY_F5
KEY_F6
KEY_F7
KEY_F8
KEY_F9
KEY_ESCAPE
KEY_CTRL
KEY_SHIFT
KEY_ALT
KEY_MENU
KEY_LBRACKET
KEY_RBRACKET
KEY_SEMICOLON
KEY_COMA
KEY_PERIOD
KEY_QUOTE
KEY_SLASH
KEY_BACKSLASH
KEY_TILDE
KEY_EQUAL
KEY_MINUS
KEY_SPACE
KEY_RETURN
KEY_BACKSPACE
KEY_TAB
KEY_PAGEUP
KEY_PAGEDOWN
KEY_END
KEY_HOME
KEY_INSERT
KEY_DELETE
KEY_PLUS
KEY_MINUS
KEY_MULTIPLY
KEY_DIVIDE
KEY_LEFT
KEY_RIGHT
KEY_UP
KEY_DOWN
KEY_PAUSE

ticks

  • in void
  • out int ticks
This is just an alias. see getTicks() for details.

triggerPlayerHitState

  • in void
  • out void

updateHP

  • in void
  • out void
Update the Health display. This is callled by tge default game handler.

updateJoyState

  • in void
  • out void
For internal use only.

uuid

  • in void
  • out string
returns a unique identifier

var_del

  • in string
  • out void
Delete a variable from global

var_get

  • in string key
  • out void
Retrieve an engine global variable.

local s = getSprite(self);
local sx, sy = getImageSize(s.imageSet, s.imageNo); 
 
if s.y + sy >= var_get("BUFFERHEI") then
  s:setState(STATE_DEAD);
  s:hide();
else
  playSound("POUFLIGHT");
  local extra = getExtra(self);
  Debug:printf("fallHeight: %d", extra.fallHeight);
  if extra.fallHeight >= 20 then
    triggerPlayerHitState();
    addToHP( -25 );
  end
end

var_set

  • in string key
  • in int value
  • out void
Register a variable with the engine.

var_set("pink_bunny", 0)

warpTo

  • in string uuid
  • in int id
  • out void
Warp to a different level. This function accepts the level's UUID or zero based index as input.

warpTo(2) 
 
warpTo("50d1-42c5-0112-e964")

XOR

  • in int a
  • in int b
  • out int binary eXclusive OR (a , b)
Exclusive OR operation.

XOR (1, 7)  -- expected resut:  6 
 
  -- explanation
  1 = 1000
  7 = 1110
    XOR
  6 = 0110 
 
  XOR (2, 3)  -- expected resut: 1 
 
  -- explanation
  2 = 0100
  3 = 1100
    XOR
  1 = 1000 
 
  etc.