Quantcast
Viewing all articles
Browse latest Browse all 911

Lua for conditional operators with strings as result.

So I wrote this simple lua function since I thought it could be useful on some especial cases, but I can't get it to work for unknown reasons, since it works fine on the lua console.

Code:

function conditional(cond, true_str, false_str)    if cond then        return true_str    else        return false_str    endend
It should let you input a conditional and output a string based on the result.

So this:

Code:

print(conditional(10 > 18, 'Yes', 'No'))
Prints: No

Here you can check that's true: https://onecompiler.com/lua/42vdzfkm4

The problem is that rainmeter will always return true (yes) no matter what.

Example skin:

#@#Script.lua

Code:

function conditional(cond, true_str, false_str)if cond then        return true_str    else        return false_str    endend
Test.ini

Code:

[Rainmeter]Update=1000DynamicWindowSize=1AccurateText=1[Script]Measure=ScriptScriptFile=#@#Script.luaUpdateDivider=-1DynamicVariables=1[Condition]Measure=StringString=[&Script:conditional(10 > 18,'Yes','No')]UpdateDivider=-1DynamicVariables=1[MeterResult]Meter=StringFontFace=ConsolasFontColor=225,255,255,255SolidColor=9,25,25,255Padding=5,5,5,5FontSize=18AntiAlias=1MeasureName=ConditionText="Condition result: %1"DynamicVariables=1
The result should be no, but it's yes.. Somehow.

I'm guessing the problem is a syntax one, so please enlighten me with your knowledge Image may be NSFW.
Clik here to view.
:)
.

I already tried '10 > 18', ''10 > 18'', "10 > 18", (10 > 18), '(10 > 18)' without luck. There's also no errors on the log.
I edit this post to list all solutions in here:

Using simple lua if statements corrected by SilverAzide

Using lua string compilation (loadstring) by nek

Using ParseFormula by Crest

Example skins + fix to shape option logging invalid shape error

Another fix to shape option logging invalid shape error

Fix to container option loging invalid container error


Any other contribution is welcome.

Statistics: Posted by RicardoTM — October 17th, 2024, 9:36 pm — Replies 11 — Views 521



Viewing all articles
Browse latest Browse all 911

Trending Articles