You are viewing an old version of this page. Return to the latest version.
Difference between revisions of "LUA:GetServerVariable"
Patrikpatrik (talk | contribs) (→Notes) |
Patrikpatrik (talk | contribs) (→Notes) |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 2: | Line 2: | ||
== GetServerVariable() == | == GetServerVariable() == | ||
| − | Gets the value of the server variable | + | Gets the value of the server variable only set by lua via [[LUA:SetServerVariable|SetServerVariable()]]. When using this function, ignore adding the 'lua_' prefix to your parameter. |
| − | |||
== Syntax == | == Syntax == | ||
| Line 33: | Line 32: | ||
If the server variable is not a number then tonumber returns nil, hence the check for nil. | If the server variable is not a number then tonumber returns nil, hence the check for nil. | ||
| − | Also, if the value is a string, for example a 'motd' variable, or an existing non ' | + | Also, if the value is a string, for example a 'motd' variable, or an existing non 'lua_' prefix variable_name, it will return as NULL. Use [[LUA:GetVariableValue|GetVariableValue()]] instead for these conditions. |
Latest revision as of 19:34, 8 August 2016
LUA - GetServerVariable
Return to: LUA | Tutorials | Portal | Forum | Project Manager | Bug Tracker
GetServerVariable()
Gets the value of the server variable only set by lua via SetServerVariable(). When using this function, ignore adding the 'lua_' prefix to your parameter.
Syntax
var = GetServerVariable(param1)
Parameters
- Required - param1 (String)
- param1 is the name of the server variable to get
Returns
- String
Usage
function hailed(NPC, Spawn)
local var = tonumber(GetServerVariable("Quest1_Global_Complete_Count"))
if var == nil or var <= 4000 then
OfferQuest(Spawn, Quest1)
else
OfferQuest(Spawn, Quest2)
end
end
This will offer the player a different quest if the server variable Quest1_Global_Complete_Count is less then or equal to 4000
Notes
If the server variable is not a number then tonumber returns nil, hence the check for nil.
Also, if the value is a string, for example a 'motd' variable, or an existing non 'lua_' prefix variable_name, it will return as NULL. Use GetVariableValue() instead for these conditions.