Module:LuaVar: Difference between revisions
From IdleOn MMO Wiki
imported>Kiokurashi (Created page with "local LuaVar = {} VariablesLua = mw.ext.VariablesLua function LuaVar.varDefine(frame) local name = frame.args.name local name = frame.args.value VariablesLua.vardefine( na...") |
Kiokurashi (talk | contribs) No edit summary |
||
(10 intermediate revisions by 2 users not shown) | |||
Line 4: | Line 4: | ||
function LuaVar.varDefine(frame) | function LuaVar.varDefine(frame) | ||
local name = frame.args.name | local name = frame.args.name | ||
local | local value = frame.args.value | ||
VariablesLua.vardefine( name, value ) | VariablesLua.vardefine( name, value ) | ||
end | end | ||
Line 10: | Line 10: | ||
function LuaVar.varDefineEcho(frame) | function LuaVar.varDefineEcho(frame) | ||
local name = frame.args.name | local name = frame.args.name | ||
local name = frame.args.value | local value = frame.args.value | ||
VariablesLua. | local data = VariablesLua.vardefineecho( name, value ) | ||
return data | |||
end | |||
function LuaVar.var(frame) | |||
local name = frame.args.name | |||
local data = VariablesLua.var( name, name .. " is undefined." ) | |||
return data | |||
end | |||
function LuaVar.exists(frame) | |||
local name = frame.args.name | |||
local data = VariablesLua.varexists( name ) | |||
return data | |||
end | |||
function LuaVar.append(frame) | |||
local name = frame.args.name | |||
local value = frame.args.value | |||
local last = "" | |||
if VariablesLua.varexists( name ) == true then last = VariablesLua.var( name ) end | |||
local data VariablesLua.vardefine( name, last .. value ) | |||
return data | |||
end | |||
function LuaVar.add(frame) | |||
local name = frame.args.name | |||
local addv = tonumber(frame.args.addv) | |||
local value = VariablesLua.var( name, tonumber(0) ) | |||
value = value + addv | |||
VariablesLua.vardefine( name, value ) | |||
return data | |||
end | end | ||
return LuaVar | return LuaVar |
Latest revision as of 14:06, 27 December 2022
Basics - Capitalization of LuaVar and the function (example varDefine) is required.:
To define a variable without returning the value:
{{#invoke:LuaVar|varDefine |name= Variable Name |value= Value }}
To define a variable and return the value:
{{#invoke:LuaVar|varDefineEcho |name= Variable Name |value= Value }}
To retrieve the value of a variable. Will inform if the variable is not defined.
{{#invoke:LuaVar|var |name= Variable Name }}
local LuaVar = {}
VariablesLua = mw.ext.VariablesLua
function LuaVar.varDefine(frame)
local name = frame.args.name
local value = frame.args.value
VariablesLua.vardefine( name, value )
end
function LuaVar.varDefineEcho(frame)
local name = frame.args.name
local value = frame.args.value
local data = VariablesLua.vardefineecho( name, value )
return data
end
function LuaVar.var(frame)
local name = frame.args.name
local data = VariablesLua.var( name, name .. " is undefined." )
return data
end
function LuaVar.exists(frame)
local name = frame.args.name
local data = VariablesLua.varexists( name )
return data
end
function LuaVar.append(frame)
local name = frame.args.name
local value = frame.args.value
local last = ""
if VariablesLua.varexists( name ) == true then last = VariablesLua.var( name ) end
local data VariablesLua.vardefine( name, last .. value )
return data
end
function LuaVar.add(frame)
local name = frame.args.name
local addv = tonumber(frame.args.addv)
local value = VariablesLua.var( name, tonumber(0) )
value = value + addv
VariablesLua.vardefine( name, value )
return data
end
return LuaVar