GAE/Lua

From MegaGlest
Revision as of 02:04, 29 September 2009 by Silnarm (talk) (Created page with ' === consoleMsg( text ) === Writes a message to the console.  This is intended for debugging purposes, the text is not looked up in the lng file. Parameters:<br />'''t…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search




consoleMsg( text )

Writes a message to the console.  This is intended for debugging purposes, the text is not looked up in the lng file.

Parameters:
text - the text to write to the console.



scenarioDir()

Returns the scenario's path relative to the executable, useful for defining scripts in external files and including them with dofile()/loadfile().

Example:

<startup>
-- load and run 'foo.lua' which is located in this scenario's directory
local chunk, error = loadfile( scenarioDir() .. "foo.lua" )
if chunk == nil then
    consoleMsg( error ); -- error
else
    chunk(); -- Ok, run chunk
end
</startup>



playerName( factionIndex )

Returns the name of the player of the given index

Parameters:
factionIndex - the faction index of the player whose name you desire.




setTimer( name, type, interval, periodic )

Sets up and starts a timer, you then create 'timer' events in the XML to match the name.

Parameters:
name - a name for the timer. This is used for your callback event.

type - the type of timer, either "game" or "real", meaning measured in game time, or real time.

interval - the timer interval, number of frames for type "game", number of seconds for "real".

periodic - false if this is a 'one-shot' event, true for a repeating event.



stopTimer( name )

Stops a named timer.

Parameters:
name - the name for the timer to stop.

example:

<startup>
    -- start a timer, to go off every 5 seconds of 'play' time (at normal speed)
    setTimer( "boo", "game", 40*5, true ) 
    numBoos = 0
</startup>

<timer name="boo">
    showMessage( "Boo", "..." )
    numBoos = numBoos + 1
    if numBoos == 3 then stopTimer( "boo" ) end
</timer>