Cafu Engine
ci Class Reference

Class ci provides access to the Cafu in-game console from other scripts (e.g. map scripts, GUI scripts, ...). More...

Public Member Functions

any GetValue (string name)
 Retrieves the value of the specified console variable. More...
 
 SetValue (string name, any value)
 Sets the console variable of the given name to the given value. More...
 
tuple LineCompletion (string LineBegin)
 This method provides command-line completion for this console interpreter. More...
 
 RunCommand (string command)
 Runs the console command command as if the user had typed it into the Cafu in-game console. More...
 

Detailed Description

Class ci provides access to the Cafu in-game console from other scripts (e.g. map scripts, GUI scripts, ...).

Note that you don't have to create instances of this class yourself. Instead this class is used like a (Lua) library: A global instance ci is automatically available. See the function details below for examples on usage.

Member Function Documentation

any GetValue ( string  name)

Retrieves the value of the specified console variable.

Example:
local showFPS = ci.GetValue("showFPS")
Parameters
nameThe name of the console variable whose value is to be retrieved.
Returns
The value of the given console variable. The returned value can be of type string, integer, boolean or number, depending on the type of the console variable, or nil if the console variable has a different type or does not exist.
tuple LineCompletion ( string  LineBegin)

This method provides command-line completion for this console interpreter.

It returns all available completions for the last token in the given parameter string LineBegin. Note that the completions not only cover the registered C++ ConFuncTs and ConVarTs, but also any other user- and implementation-defined symbols.

Parameters
LineBeginThe incomplete command-line string for whose last token the function is supposed to provide completions for. For example, if LineBegin is "a=GetValueX()*Get", the method is supposed to look for completions for "Get".
Returns
A (string, table) tuple whose first element is the longest expansion substring for LineBegin that works with all completions. The caller can simply concatenate this string to LineBegin to implement incremental completions. The second element is the table with all found completions as complete tokens.
RunCommand ( string  command)

Runs the console command command as if the user had typed it into the Cafu in-game console.

Use this to run console functions and to set the values of console variables.

Examples:
ci.RunCommand("quit = true") -- Same as ci.SetValue("quit", true)
ci.RunCommand("changeLevel('TechDemo')")
ci.RunCommand("SetMasterVolume(0.8)")
Also see the *.cgui files in DeathMatch/GUIs for many additional examples.
Parameters
commandThe command (including paramaters etc.) to be run in the in-game console.
SetValue ( string  name,
any  value 
)

Sets the console variable of the given name to the given value.

Example:
ci.SetValue("showFPS", true)
Parameters
nameThe name of the console variable whose value is to be set.
valueThe value that the console variable is set to. Note that value can be of any type; it is cast to the type of the console variable. If the cast fails, some default value is assigned to the console variable.