This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

grp.getvalue() returned value
#1
Hi all,

here a very simple question.
What type of data does grp.getvalue() return?

I didn't understand why this code works
    
    variable  = grp.getvalue('1/1/1')
    if (variable == true) then...    

while this not

    variable  = grp.getvalue('1/1/1')
    if (variable == 1) then ...


1/1/1 is defined on LM as 01.001 Switch
Reply
#2
For 01.X types it returns a Boolean value (true/false). In Lua true does not equal 1.
Reply
#3
Thanks.

For the future... where can I find such informations to avoid similar silly questions? :-)

That's what the reference manual says:
"Returns value for the given alias or nil when object cannot be found."
Reply
#4
This is more of a Lua language thing. As described in the manual:
Equality (==) first compares the type of its operands. If the types are different, then the result is false (https://www.lua.org/manual/5.1/manual.html#2.5.2)
This is what happens if you try to compare true or false to 1.
Reply
#5
Ok, sorry for my unclear question.

What I meant was: where can I find the information that grp.getvalues() method returns a boolean value (true/false) if the reference manual only says "Returns value for the given alias or nil when object cannot be found."?
Reply
#6
The value type depends on the datatype. In most cases it will be a number but can also be a Boolean, string or table. You can use log(value) to see what the function returns.
Reply


Forum Jump: