It is currently April 24th, 2024, 7:44 am

GetVariable() returns nil?

Discuss the use of Lua in Script measures.
User avatar
XANCI
Posts: 104
Joined: September 18th, 2011, 6:37 am
Location: Nanjing, China

GetVariable() returns nil?

Post by XANCI »

In Manual:

Code: Select all

GetVariable(string name)
Returns the value of the given variable. If the variable is not found, returns nil.
But, if var1 doesn't exist, type(SKIN:GetVariable('var1')) will fail and return a error message in Log:Script: xxx.lua:X: bad argument #1 to 'type' (value expected)
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: GetVariable() returns nil?

Post by poiru »

Thanks, will fix for 2.4 beta. For now, you can use:

Code: Select all

type(SKIN:GetVariable('var1') or nil)
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: GetVariable() returns nil?

Post by jsmorley »

You can also use:

TestVar = SKIN:GetVariable('NoVar')
TestType = type(TestVar)