It is currently October 22nd, 2024, 6:49 pm

Lua for conditional operators with strings as result.

Discuss the use of Lua in Script measures.
RicardoTM
Posts: 404
Joined: December 28th, 2022, 9:30 pm
Location: México

Re: Lua for conditional operators with strings as result.

Post by RicardoTM »

Yincognito wrote: Yesterday, 12:26 pm Ouch, it was that bad? :lol:
Just joking, may he live to throw better and better parties - and thanks! A good mystery is sometimes more interesting than mundane stuff, though both should be appreciated while they last. ;-)
I organized the party at home lol I should call it family reunion though. He turned 39 and has never thrown a party, at least not that I know :lol: Fortunately there's many years ahead for him to throw one at least once.

I do enjoy spending time with my family and I appreciate it, it's just that I enjoy a good mistery way more than having mundane conversations. Some good jokes were present though, so no wasted time whatsoever :lol:.

Anyway, returning to the topic of this thread. I couldn't test the idea I had with the function I wrote earlier. It didn't work, it was brilliant on my mind :rofl:

Now I can't come up with anything to call the lua's math() function from rainmeter, to be more clear:

If the SectionIndex function is used in some position option that requires a formula, it will log a invalid formula error on first load and refresh, so the idea is to use lua for the math as well, that way rainmeter would think that position option equals 0 on first load and refresh and wouldn't log any error.

To be more clear:

Code: Select all

[Meter5]
...
Y=45

[Meter5Something]
H=45
...
Y=([Meter[&S:SI()]:Y]+[[#CurrentSection]:H])
That would log that [Meter0 - invalid formula - blah blah.

So my idea is to do:
Y=[&S:math([Meter[&S:SI()]:Y]+[[#CurrentSection]:H])]
That should not log any error.
RicardoTM
Posts: 404
Joined: December 28th, 2022, 9:30 pm
Location: México

Re: Lua for conditional operators with strings as result.

Post by RicardoTM »

Just in case you read that I deleted all the previous post by mistake, I rewrote it :thumbup: lol

Edit.

I found the way:

Code: Select all

function Math(formula)
 return tonumber(formula)
 end
It was that easy lol

Code: Select all

[Test9]
...
Y=5

[Test9Something]
...
H=5
Y=[&C:Math(([&Test[&C:SI()]:Y]+[&[#CurrentSection]:H]))]
...
DynamicVariables=1
That will correctly do Y=10 without any errors.
User avatar
Yincognito
Rainmeter Sage
Posts: 8534
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Lua for conditional operators with strings as result.

Post by Yincognito »

RicardoTM wrote: Yesterday, 2:57 pm Just in case you read that I deleted all the previous post by mistake, I rewrote it :thumbup: lol

Edit.

I found the way:

Code: Select all

function Math(formula)
 return tonumber(formula)
 end
It was that easy lol

Code: Select all

[Test9]
...
Y=5

[Test9Something]
...
H=5
Y=[&C:Math(([&Test[&C:SI()]:Y]+[&[#CurrentSection]:H]))]
...
DynamicVariables=1
That will correctly do Y=10 without any errors.
Nice - hopefully it will work for all cases. Me, I noticed that nesting inline Lua from Rainmeter can be tricky, but maybe it was just my scenario at the time. ;-)
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
RicardoTM
Posts: 404
Joined: December 28th, 2022, 9:30 pm
Location: México

Re: Lua for conditional operators with strings as result.

Post by RicardoTM »

Yincognito wrote: Today, 6:59 am Nice - hopefully it will work for all cases. Me, I noticed that nesting inline Lua from Rainmeter can be tricky, but maybe it was just my scenario at the time. ;-)
Time will tell. For now it haven't caused any error at all.