Skyline Lua API  Version 1.0 RC1
Lua Script Reference for Skyline Game Engine.
Basic_Syntax Class Reference

#include <LUA_API_Syntax.h>

Public Member Functions

 Loop_For ()
 The Classic For Loop. More...
 
 Loop_While ()
 The Classic While do Loop. More...
 
 if_then_else_end ()
 The use of if then else end give your scipts the ability to make desicians. More...
 
 Strings ()
 String types are a very common type when scripting and will be called upon again and again.These types contain words rather than numbers. More...
 
 Variable ()
 Lua variables can be used for passing information between different sections of the script or for remembering game play data etc. String type variables contain text where as int and float contain a numeric value, float contains the extra values after the decimal point
Note: variable names can not begin with digits, but digits may follow letters. (2health = wrong health2 = correct) More...
 
 Functions ()
 Provide self contained blocks of code which can be called from various locations in your script. These code blocks can have values passed as arguments and return a value back to the calling code. More...
 
 Comments ()
 Comments enable us to leave remarks or information in our scripts or comment out a line of code when prototyping and degugging. When making a new function it is advisable to add a comment just before the function to describe what the function does or the argumernts needed. The syntax for a comment comes in 2 ways, one way for a single comment and anther for block comments. More...
 
 SemiColons ()
 Semi colons are traditionally part of variable naming, however Lua does not require a statement to end in a semicolon. The following two examples are identical. More...
 
 CamelCasing ()
 A term used in coding to decscribe how to use twin named variable. More...
 
 Array ()
 Arrays can be used to contain index lists of variables. More...
 

Detailed Description

When working with any coding platform it is important that the correct sysntax is used. This section of the Skyline Scripting API covers the basic syntax required when developing your project on the Skyline Game Engine. With Lua being an avanced highlevel application development language there are many ways to do similar tasks and not all the features are required or exist when used as a script extension. We are always improving the scripting system and more features are being added every week. Please experiment to uncover undocumented features as some may exist we endevour to keep this page update with new syntaxs that are gauranteed to work when scripting on Skyline.

Lua ignores spaces (including new lines) and comments between commands, except as delimiters between names and keywords such as .

Names (also called identifiers) in Lua can be any string of letters, digits, and underscores, not beginning with a digit. Identifiers are used to name variables, table fields, and labels.

The following keywords are reserved and cannot be used as names:

     and       break     do        else      elseif    end
     false     for       function  goto      if        in
     local     nil       not       or        repeat    return
     then      true      until     while

Lua is a case-sensitive language: eg var and VAR are two different valid names.
The following strings denote other tokens:

     +     -     *     /     %     ^     #
     ==    ~=    <=    >=    <     >     =
     (     )     {     }     [     ]     ::
     ;     :     ,     .     ..    ...

Literal strings can be delimited by matching single or double quotes, and can contain the following C-like escape sequences: '' (bell), '' (backspace), '' (form feed), '
' (newline), '' (carriage return), '' (horizontal tab), '' (vertical tab), '\' (backslash), '"' (quotation mark [double quote]), and '\'' (apostrophe [single quote]). A backslash followed by a real newline results in a newline in the string. The escape sequence '' skips the following span of white-space characters, including line breaks; it is particularly useful to break and indent a long literal string into multiple lines without adding the newlines and spaces into the string contents.

Precedence:
Operator precedence in Lua follows the table below, from lower to higher priority:

     or
     and
     <     >     <=    >=    ~=    ==
     ..
     +     -
     *     /     %
     not   #     - (unary)
     ^

As usual, you can use parentheses to change the precedences of an expression. The concatenation ('..') and exponentiation ('^') operators are right associative. All other binary operators are left associative.

Member Function Documentation

Basic_Syntax::Array ( )

Arrays can be used to contain index lists of variables.

eg:

local people = {}

people[1] = "Tim"
people[2] = "John"
people[3] = "Sam"
people[4] = "Miller"

In lua you can use multi-dimentioanl arrays as an arary of an array! This is better understood with an example:#

eg:
lets look at an array of people and their age.

local people = {}
people[1] = {}

this defines people[1] with a new arry so we can have

people[1][1] = "Tim"
people[1][2] =  21

A better and easier to read way would be:

people = 
{
    {"Tim",21}      --name = people[1][1] and age = people[1][2]
    {"John",35}     --name = people[2][1] and age = people[2][2]
    {"Miller",40}   --name = people[3][1] and age = people[3][2]
}

to get millers age we would look at:
age = people[3][2];
Basic_Syntax::CamelCasing ( )

A term used in coding to decscribe how to use twin named variable.

Names can not have spaced in them. This is problematic for names that are longer than one word. This is fixed by capitalizing the beginning of each word after the first word. This is known as camel casing.

eg:

motorsport = true;

or 

motorSport = true;
Basic_Syntax::Comments ( )

Comments enable us to leave remarks or information in our scripts or comment out a line of code when prototyping and degugging. When making a new function it is advisable to add a comment just before the function to describe what the function does or the argumernts needed. The syntax for a comment comes in 2 ways, one way for a single comment and anther for block comments.

eg:
-- This is a single line comment

-- The following line of code will not run.
-- var = 25;

--[[
    Multiple lines of code or text can be used in a comment block.
    This block has a start and an end syntax. 
]]--
Basic_Syntax::Functions ( )

Provide self contained blocks of code which can be called from various locations in your script. These code blocks can have values passed as arguments and return a value back to the calling code.

Defining a basic function:

eg:

function functionName()
     -- Body of a function.
end

functionName();

Defining a basic function with two arguments:

eg:

function myFunction(String text, float value)
     myText = text;
     myValue = value;
end

myFunction("hello",10);

Defining a basic function which returns a value:

eg:

function getValue(float value)
    myValue = value * 2;
    return myValue;
end

test = getValue(20);
sky.lprint(test); -- this will print 40 to the console.
Basic_Syntax::if_then_else_end ( )

The use of if then else end give your scipts the ability to make desicians.

eg:

if( health < 0 ) then
    --Player KO
    doPlayerKOAnimation();
else
    --Health is ok so keep attacking
    attackNPC();
end

if ( ammo == 1 ) then
    keepShooting();
elseif (ammo == 2 ) then
    addPowerup();
end
Basic_Syntax::Loop_For ( )

The Classic For Loop.

The break code can be used to exit the loop. In a situation with one or more nested loops, only the innermost loop will ever be terminated.

The following is a Small Example on how to use this function:

for variable = value, end value, step  do
    -- Your chunk here.
end


for i = 1, 10 do -- Start our loop, which sets i to 1 and runs until i reaches 10.
    print( i ) -- Print i, which gets increased each time.
end -- End the loop.


for i = 1, 10, 2 do -- Make a new loop, the step is 2 instead of 1.
    print( i ) -- Print i
end -- End the loop.


for i = 1, 10  do
    if ( i == 5 ) then break end
    print( i )
end
Basic_Syntax::Loop_While ( )

The Classic While do Loop.

The following is a Small Example on how to use this function:

while condition do
    -- Your chunk.
end

local a = 3 -- Make a local variable with the value of 3.

while ( a == 3 ) do -- Run as long as a is 3.
    a = 4 -- Set a to 4
end -- End the loop.
Basic_Syntax::SemiColons ( )

Semi colons are traditionally part of variable naming, however Lua does not require a statement to end in a semicolon. The following two examples are identical.

eg:
apples = "apples"
bananas = "bananas" oranges = "oranges"

apples = "apples"; 
bananas = "bananas";  oranges = "oranges";

Ending statements in a semicolon is a convention deriving from C. The majority of Lua coders tend to not end statements with semicolons. Semi colons may be used for whatever stylistic purpose, often to improve code readability by separating unlike sets of statements.

Basic_Syntax::Strings ( )

String types are a very common type when scripting and will be called upon again and again.These types contain words rather than numbers.

Strings can be joined together or text lines can be prepended to a number such as "Player Health: 10"

eg:

health = 25;
text = "Player Health: "..health;

When working with long lines of text you can use the multiline syntax [[ text body ]]

eg:

text = [[
this text
spans many
lines
]]
Basic_Syntax::Variable ( )

Lua variables can be used for passing information between different sections of the script or for remembering game play data etc. String type variables contain text where as int and float contain a numeric value, float contains the extra values after the decimal point
Note: variable names can not begin with digits, but digits may follow letters. (2health = wrong health2 = correct)

eg:
String  myString    = "Ten";

int     value       = 10;

float   value       = 10.12345;

The following example takes a string variable and passes its contents to the lprint function.

function onInit(objID)
    text = "hello world";
    sky.lprint(text);
end

The documentation for this class was generated from the following file: