Quantcast
Channel: Rainmeter Forums
Viewing all articles
Browse latest Browse all 1407

Lua Scripting • Re: Lua for conditional operators with strings as result. [Help]

$
0
0
There are multiple problems here, so welcome to the Rainmeter/Lua mashup world.

First, from the Rainmeter side, the Rainmeter parser doesn't always know when to parse a string and when not to. In this case, you will find that if you remove the spaces from the conditional expression, it will work. So this...

Code:

String=[&Script:conditional((10>18),'Yes','No')]
...will work.

BUT WAIT! Before you try it, you need to fix your Lua code. The problem is you've missed this tidbit from the Lua manual (section 2.2, Booleans)
Beware that, unlike some other scripting languages, Lua considers both zero and the empty string as true in conditional tests.
So change your code to:

Code:

    if cond == 0 then        return false_str    else        return true_str    end
(Note that I've flipped your expression around to my preferred style.) If you add the following debug code to your function...

Code:

    print("cond = " .. cond .. " and is of type " .. type(cond))
... you'll see that your original code was passing 10. ( :confused: )

Statistics: Posted by SilverAzide — Yesterday, 10:50 pm



Viewing all articles
Browse latest Browse all 1407

Trending Articles