Skyline Lua API
Version 1.0 RC1
Lua Script Reference for Skyline Game Engine.
|
#include <LUA_API_Sky.h>
Public Member Functions | |
void | callGlobalFn (entityID, value) |
Call this command to trigger all entities script globalFn() event. More... | |
void | callModuleEvent (int callingID, int targetID, string key, string type, string value) |
Call this command to send an event and data to a specified objects graph's "Lua Event" module. More... | |
void | luaModuleOut (int objID, string key, string value, string optional_type) |
Call this command to send data out of this lua module. More... | |
void | lprint (string text) |
Prints the content of the variable text to the console. More... | |
void | trace () |
A debugging function that will print a noticable line of text to the console. Very handy when following the flow of the code. More... | |
void | setGameState (int gameState) |
Call this function to change the current game state. This function in the sky.library() is depreciated, please see the state.setGameState() function. More... | |
int | getGameState () |
Call this function to return the current Game State. This function in the sky.library() is depreciated, please see the state.getGameState() function instead. More... | |
void | setVar (string variableName, string value) |
This function is used when you require the service of a global variable. This variable will be available to all scripts. More... | |
string | getVar (string var) |
Receive the data stored in the global variable named var. More... | |
void | setTable (string tableName, table) |
This function is used when you require the service of a global Table. This table will be available to all the scene objects scripts. Important: The table must contain pairs of key/value in order for this command to work eg .Season = {q1="Spring",q2="Summer",q3="Autmn",q4="Winter"} . More... | |
string | getTable (table) |
Receive the data stored in the global table named table Important: The table must contain pairs of key/value in order for this command to work eg .Season = {q1="Spring",q2="Summer",q3="Autmn",q4="Winter"} . More... | |
void | printTable (table) |
This function will print out to the console all of the table key:value Important: The table must contain pairs of key/value in order for this command to work eg .Season = {q1="Spring",q2="Summer",q3="Autmn",q4="Winter"} . More... | |
float3 | raycastToCursor (float posx, float posy, float posz) |
Cast a ray from the screen cursor to any object in 3D world space and return its position. More... | |
int | getSceneScriptID () |
Returns the scene script ID. More... | |
void | print (String text, optional int singleLineState) |
Prints the contents of the string text to the game overlay console. More... | |
void | ui_changeInterface (String workspace, String MyUI) |
Prints the contents of the string text to the game overlay console. More... | |
void | ui_clear () |
Clears the simple console. More... | |
void | ui_setFontColor (|String color) |
Sewts the font color for the simple console. More... | |
void | loadScene (String sceneFileName) |
Dynamically loads a scene. More... | |
void | exitEnable (bool state) |
Prevents the system from using the ESC key to close down the player. More... | |
void | exit () |
Exits the game. More... | |
void | getMouseDelta () |
This function returns you the X and Y mouse move deltas calculated within the engine. More... | |
void | suppressErrors (int state) |
Use this function as a performance helper. It stops all messages from being printed to the DOS Console and the Skyline Console This is useful, when trying to see if your game will run smoothly when spawning presets that look like they cause a pop. This is because any time the engine makes a print to the log or DOS, the framerate can stutter. More... | |
void | include (String filename) |
This will copy the contents of a lua script into the top of the current script inside lua. When used, the lua code is automatically executed allowing use of functions and variables instantly. The file is found in the resources and builds a path to the location whether it is runnning in the editor, player or end game. More... | |
void sky | getDir_GameAssets () |
return the compiled and ran game folder More... | |
void sky | getDir_GameRoot () |
This will return the Root of the compiled game folder. Great for mods or save files. More... | |
void sky | luaModuleOut (obj, key, value, optional_type) |
Call an object and send a recieve graph "LUA EVENT". luaModuleOut() calls the selected object with targetID and sends to a graph with a receiving module "Lua Event" identified by key. More... | |
void sky | callModuleEvent (callingID, targetID, key, type, value) |
callModuleEvent(). callModuleEvent() calls the selected object with targetID and sends to a graph with a receiving module "Lua Event" identified by key More... | |
void | restartGame () |
restartGame(). restartGame() exit the game and restart the player for use with game player and end game. More... | |
Public Attributes | |
int | id = sky.getSelectedID() |
get selected ID. getSelectedID() gets the id for selected object. Editor side lua only More... | |
int | sceneScriptId |
get scene script ID. getSceneId() gets the scene id for scnee script events scenes currently have a special id=-9 to differentiate between scene scripts and object script intercommunication. More... | |
The sky class is responsible for handling ray casting and general global scene settings
Use as sky.function()
For more information on how these functions can be used please visit the User Manual - http://www.chi-ad.com/Skyline/SDN/
void sky::callGlobalFn | ( | entityID | , |
value | |||
) |
Call this command to trigger all entities script globalFn() event.
entityID | : The Entity ID calling this command. |
value | : Any value you want ot pass through the event. |
Use this command when you would like to trigger the globalFn() event in all active scripts.
A value can be passed between scripts by using the value argument.Note that this command makes a call to all
active scripts and in a scene with many scripts this may take a few frames so best not to call in an update loop.
Here is a Small Example of how to use this function:
function onKeyDown( key ) if(key=="space") then sky.callGlobalFn(obj,1); end end -- In all of the receiving scripts. function globalFn( callingID, value ) sky.lprint("Dynamic Object:"..obj.." Calling ID="..callingID.." value="..value); end
void sky::callModuleEvent | ( | int | callingID, |
int | targetID, | ||
string | key, | ||
string | type, | ||
string | value | ||
) |
Call this command to send an event and data to a specified objects graph's "Lua Event" module.
callingID | : The Entity ID calling this command. |
targetID | : The target Entity's ID . |
Key | : the receiving module must match this key |
Type | : the type of value, either blank "" or advanced "int" , "bool", "string", "float" |
value | : the string value you would like to send to the graph |
Use the callModuleEvent(..) command to send data to an active graph's "Lua Event" module which
has the corrisponding "key". Type fo most cases can be left as "" but if you need to send a specifict type then
specify it in the type argument. Most modules can accept strings and auto typecast when needed.
Here is a Small Example of how to use this function:
function onKeyDown( key ) sky.callModuleEvent(callingID, targetID, "module1", ", "hello world!" ) end
void sky sky::callModuleEvent | ( | callingID | , |
targetID | , | ||
key | , | ||
type | , | ||
value | |||
) |
callModuleEvent(). callModuleEvent() calls the selected object with targetID and sends to a graph with a receiving module "Lua Event" identified by key
void sky.callModuleEvent(callingID, targetID, key, type, value );
void sky::exit | ( | ) |
Exits the game.
The game will exit when this command is called.
The following is a Small Example on how to use this function:
function onInit(objID) sky.exitEnable(0); end function onKeyDown( key ) if(key=="esc") then sky.exit(); end end
void sky::exitEnable | ( | bool | state | ) |
Prevents the system from using the ESC key to close down the player.
state | : Either 1 or 0 representing true/false. |
This command prevents the system from using the ESC key to close down the player.
Warning: Once called sky.exitEnable(0) there is no way to shut down the player other than the standard windows methods.
You must manage your own exit system either from a gui menu or a key press of your choice.
The following is a Small Example on how to use this function:
function onInit(objID) sky.exitEnable(0); end function onKeyDown( key ) if(key=="esc") then sky.exit(); end end
void sky sky::getDir_GameAssets | ( | ) |
return the compiled and ran game folder
This will return the Assets folder of the compiled and ran game.
AssetDIR = sky.getDir_GameAssets();
void sky sky::getDir_GameRoot | ( | ) |
This will return the Root of the compiled game folder. Great for mods or save files.
This will return the Root of the compiled game folder. Great for mods or save files.
gameRDir = sky.getDir_GameRoot();
int sky::getGameState | ( | ) |
Call this function to return the current Game State. This function in the sky.library() is depreciated, please see the state.getGameState() function instead.
The following is a Small Example on how to use this function:
function onInit(objID) curentState = sky.getGameState(); end
void sky::getMouseDelta | ( | ) |
This function returns you the X and Y mouse move deltas calculated within the engine.
The following is a Small Example on how to use this function:
function onMouseMove( ms_pos_x, ms_pos_y ) mouseDelta = newType.vec2(sky.getMouseDelta()); sky.print("mouseDelta X: "..mouseDelta.x.."</br>mouseDelta Y : "..mouseDelta.y, 1); end
int sky::getSceneScriptID | ( | ) |
Returns the scene script ID.
The following is a Small Example on how to use this function:
function onInit(objID) sceneScriptId = sky.getSceneScriptID() end
string sky::getTable | ( | table | ) |
Receive the data stored in the global table named table
Important: The table must contain pairs of key/value in order for this command to work eg .Season = {q1="Spring",q2="Summer",q3="Autmn",q4="Winter"}
.
table | : The name of the table you would like to return from global memory. |
The following is a Small Example on how to use this function:
year = { calander = { month = {m1="jan",m2="feb",m3="march",m4="apr",m5="may"}, day = {d1="M",d2="T",d3="W",d4="T",d5="F",d6="S",d7="S"}, Season = {q1="Spring",q2="Summer",q3="Autmn",q4="Winter"} }, Time = { T1="start", T2="Stop", mins = { min1_15="Qurter past", min2_15="Halfpast", min3_15="Quarter To", min4_15="Hour", }, Types = {t1="ms",t2="sec",t3="mins",t4="Hours",t5="days"} } }; function onInit(objID) --set the table to global memory sky.setTable("year",year); --This can be called from another objects script. --get the table from global memory and store in var t t = sky.getTable("year"); --printout to the console the new table sky.printTable(t); sky.lprint("\nMonth 3: "..t.calander.month.m3); end
string sky::getVar | ( | string | var | ) |
Receive the data stored in the global variable named var.
var | : The name of the variable you would like to return from global memory. |
The following is a Small Example on how to use this function:
function onInit(objID) value = sky.getVar("var name"); end
void sky::include | ( | String | filename | ) |
This will copy the contents of a lua script into the top of the current script inside lua. When used, the lua code is automatically executed allowing use of functions and variables instantly. The file is found in the resources and builds a path to the location whether it is runnning in the editor, player or end game.
This is also useful to base class data. See "Asset Library/Scripts/Base Classes/BaseClasses.lua" for a running example of using base classes with skyline.
FileName | : Place the name of the file without a path or slashes to include into the current script The following is a Small Example on how to use this function: -- Top of script file sky.include("Base.lua"); -- now functions and variables |
void sky::loadScene | ( | String | sceneFileName | ) |
Dynamically loads a scene.
sceneFileName | : The name of the scene to load |
This command enables you to load a scene from an already running scene, perfect for changing levels in a game.
The following is a Small Example on how to use this function:
sky.loadScene("level1");
void sky::lprint | ( | string | text | ) |
Prints the content of the variable text to the console.
text | :A string containing the text to be printed to the console. |
You must have the console window open to see the results of this command.
The following is a Small Example on how to use this function:
function onInit(objID) sky.lprint("Hello World\n"); end
void sky::luaModuleOut | ( | int | objID, |
string | key, | ||
string | value, | ||
string | optional_type | ||
) |
Call this command to send data out of this lua module.
objID | : The Entity ID calling this command. |
Key | : the receiving lua module's output must match this key |
value | : the string value you want back out of lua |
optional_type | : the type of value, either blank "" or advanced "int" , "bool", "string", "float" |
Use the luaModuleOut(..) command to send data out of a lua Module ie the graph contains a Simple Lua module and
would like to send data to this modules outputs.
Here is a Small Example of how to use this function:
function myKeyDown( key ) value = key; sky.luaModuleOut(obj, "EvOut_A", value ); end
void sky sky::luaModuleOut | ( | obj | , |
key | , | ||
value | , | ||
optional_type | |||
) |
Call an object and send a recieve graph "LUA EVENT". luaModuleOut() calls the selected object with targetID and sends to a graph with a receiving module "Lua Event" identified by key.
sky.luaModuleOut(obj, key, value, optional_type );
void sky::print | ( | String | text, |
optional int | singleLineState | ||
) |
Prints the contents of the string text to the game overlay console.
text | :the text to pass to the console. |
singleLineState | :Optional argument when set to 1 the console will only print out 1 line |
This console is a simple text interface for any in game feedback. This is useful in the player and end game
as there is no access to the log for debug printing. Use th efunctions ui_setFontColor to change text color
and ui_clear() to clear the consol display.
If you need to use a line break to move text to the next line use the syntax
The following is a Small Example on how to use this function:
function onInit(objID) sky.print("Hello Console line 1"); sky.print("Hello Console line 2"); end --OR function onInit(objID) sky.print("Hello Console line 1 <br/>Hello Console line 2"); end --OR function onInit(objID) sky.print("Hello Console line 1",1); -- force each print onto one line overrighting the previous text end
void sky::printTable | ( | table | ) |
This function will print out to the console all of the table key:value
Important: The table must contain pairs of key/value in order for this command to work eg .Season = {q1="Spring",q2="Summer",q3="Autmn",q4="Winter"}
.
table | :the table to examine The following is a Small Example on how to use this function: function onInit(objID) sky.printTable(table); end |
float3 sky::raycastToCursor | ( | float | posx, |
float | posy, | ||
float | posz | ||
) |
Cast a ray from the screen cursor to any object in 3D world space and return its position.
The following is a Small Example on how to use this function:
function onInit(objID) x,y,z = sky.raycastToCursor(); end
void sky::restartGame | ( | ) |
restartGame(). restartGame() exit the game and restart the player for use with game player and end game.
void sky.callModuleEvent(callingID, targetID, key, type, value );
void sky::setGameState | ( | int | gameState | ) |
Call this function to change the current game state. This function in the sky.library() is depreciated, please see the state.setGameState() function.
gameState | :An integer representing the state to be changed to. |
The currently available Game States are as follows:
1 = GS_GAMEMAIN
2 = GS_GAMEPAUSED
3 = GS_GAMESTART
4 = GS_GAMEOVER
The following is a Small Example on how to use this function:
function onInit(objID) sky.setGameState(2); end
void sky::setTable | ( | string | tableName, |
table | |||
) |
This function is used when you require the service of a global Table. This table will be available to all the scene objects scripts.
Important: The table must contain pairs of key/value in order for this command to work eg .Season = {q1="Spring",q2="Summer",q3="Autmn",q4="Winter"}
.
tableName | : This is the name to give the new global table so it can be accessed from elsewhere. Note this must be a unique name. |
table | : Pass the table contents to the global memory |
The following is a Small Example on how to use this function:
year = { calander = { month = {m1="jan",m2="feb",m3="march",m4="apr",m5="may"}, day = {d1="M",d2="T",d3="W",d4="T",d5="F",d6="S",d7="S"}, Season = {q1="Spring",q2="Summer",q3="Autmn",q4="Winter"} }, Time = { T1="start", T2="Stop", mins = { min1_15="Qurter past", min2_15="Halfpast", min3_15="Quarter To", min4_15="Hour", }, Types = {t1="ms",t2="sec",t3="mins",t4="Hours",t5="days"} } }; function onInit(objID) --set the table to global memory sky.setTable("year",year); --This can be called from another objects script. --get the table from global memory and store in var t t = sky.getTable("year"); --printout to the console the new table sky.printTable(t); sky.lprint("\nMonth 3: "..t.calander.month.m3); end
void sky::setVar | ( | string | variableName, |
string | value | ||
) |
This function is used when you require the service of a global variable. This variable will be available to all scripts.
variableName | : This is the name to give the new global variable. Note this must be a unique name. |
value | : Pass the variables contents to global memory |
The following is a Small Example on how to use this function:
function onInit(objID) anyValue = 12.43; sky.setVar("myGlobalVariable", anyValue); anyValue = sky.getVar("myGlobalVariable"); end
void sky::suppressErrors | ( | int | state | ) |
Use this function as a performance helper. It stops all messages from being printed to the DOS Console and the Skyline Console This is useful, when trying to see if your game will run smoothly when spawning presets that look like they cause a pop. This is because any time the engine makes a print to the log or DOS, the framerate can stutter.
Since this is a helper command, you have to manually turn the printing back on in your onStop(), otherwise all prints will be suppressed from editor side aswell.
state | : 1 - turn printing off, 0 - turn printing on. |
The following is a Small Example on how to use this function:
function onInit( objID ) sky.suppressErrors(1); end function onStop() sky.suppressErrors(0); end
void sky::trace | ( | ) |
A debugging function that will print a noticable line of text to the console. Very handy when following the flow of the code.
You must have the console window open to see the results of this command.
The following is a Small Example on how to use this function:
function onInit(objID) sky.trace(); end
void sky::ui_changeInterface | ( | String | workspace, |
String | MyUI | ||
) |
Prints the contents of the string text to the game overlay console.
workspace | :The workspace path to your console replacment. |
MyUI | :The UI to replace the simple console with. |
You can replace the system simple console interface with one of your own. Create your libRocket console and ensure
that you use the div id="text" for your text area so that the system knows which element to pass the text to.
NOTE: if you pass the workspace arg as "reset" the system will return to the default console. ie sky.ui_changeInterface("reset", "")
The following is a Small Example on how to use this function:
function onInit(objID) sky.ui_changeInterface("MyFolder", "MyUI") end
void sky::ui_clear | ( | ) |
Clears the simple console.
The following is a Small Example on how to use this function:
function onInit(objID) sky.ui_clear() end
void sky::ui_setFontColor | ( | |String | color | ) |
Sewts the font color for the simple console.
color | : The string representation of the color value #00FF00FF = green [# RR GG BB AA] in hex values [0-F] |
The following is a Small Example on how to use this function:
function onInit(objID) sky.ui_setFontColor("#FF0000FF"); -- red end
int sky::id = sky.getSelectedID() |
get selected ID. getSelectedID() gets the id for selected object. Editor side lua only
int id = sky.getSelectedID();
int sky::sceneScriptId |
get scene script ID. getSceneId() gets the scene id for scnee script events scenes currently have a special id=-9 to differentiate between scene scripts and object script intercommunication.
int sceneScriptId = sky.getSceneId()