It is currently September 17th, 2021, 1:26 pm

Lua and !SetOption

Discuss the use of Lua in Script measures.
User avatar
jsmorley
Developer
Posts: 22270
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Lua and !SetOption

Post by jsmorley »

One thing to remember, using !SetOption in effect ADDS the "setting" to the meter or measure if it is not already there. What that means when you are using a style is:

[Variables]
VarColor=255,255,25,255

[Style]
FontColor=#VarColor#

[MeterOne]
Meter=String
MeterStyle=Style

The FontColor will start out as 255,255,25,255, the value of #VarColor# as passed from the MeterStyle

If you use a !SetOption to set the meter's FontColor, with !SetOption MeterOne FontColor 0,0,0,255 for instance, you have now ADDED a FontColor "setting" to MeterOne. That will ALWAYS override what is in a MeterStyle. So if you change #VarColor# in some other place using !SetVariable for instance, it will have no effect on MeterOne.

You can remove a setting set by !SetOption by using !SetOption MeterOne FontColor ""
User avatar
smurfier
Moderator
Posts: 1930
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Lua and !SetOption

Post by smurfier »

Found the problem.

[mDay1] fails.
[mDayOne] works fine.
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
User avatar
jsmorley
Developer
Posts: 22270
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Lua and !SetOption

Post by jsmorley »

smurfier wrote:Found the problem.

[mDay1] fails.
[mDayOne] works fine.
Huh, if I understand correctly, it sounds like there is a missing "tostring()" somewhere and "1" is being treated as a number instead of a string by Lua someplace.
User avatar
smurfier
Moderator
Posts: 1930
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Lua and !SetOption

Post by smurfier »

Actually, i did that right in Rainmeter with the MouseOverAction. I made a whole different meter to find this out.
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
User avatar
jsmorley
Developer
Posts: 22270
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Lua and !SetOption

Post by jsmorley »

[Rainmeter]
Update=100
DynamicWindowSize=1
MouseOverAction=!SetOption mDay1 FontColor 255,255,255,255
MouseLeaveAction=!SetOption mDay1 FontColor #*Txt.Clr*#

[Variables]
Txt.Clr=255,255,25,255

[Style]
FontColor=#Txt.Clr#

[mDay1]
Meter=String
MeterStyle=Style
FontSize=15
Text=Hello

Also works fine for me.

Sure that "install" of Rainmeter actually went ok? :-)
User avatar
smurfier
Moderator
Posts: 1930
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Lua and !SetOption

Post by smurfier »

I reinstalled twice just to make sure.
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
User avatar
jsmorley
Developer
Posts: 22270
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Lua and !SetOption

Post by jsmorley »

smurfier wrote:I reinstalled twice just to make sure.
Can you test my skin from my post just above?

Should start yellow, change to white, then back to yellow on leave.
User avatar
smurfier
Moderator
Posts: 1930
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Lua and !SetOption

Post by smurfier »

I switched from using SomeMeter:SetText() to using !SetOption and all works well.

Sorry.

Now I get it...
SetText only worked without dynamicvariables and SetOption forces dynamicvariables.
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
User avatar
jsmorley
Developer
Posts: 22270
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Lua and !SetOption

Post by jsmorley »

smurfier wrote:I switched from using SomeMeter:SetText() to using !SetOption and all works well.

Sorry.

Now I get it...
SetText only worked without dynamicvariables and SetOption forces dynamicvariables.
Ah, understood. That will be something we will all need to watch for when we transition from old to new on existing skins.
User avatar
jsmorley
Developer
Posts: 22270
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Lua and !SetOption

Post by jsmorley »

Just as an aside, and in the form of a "tip" for this new stuff:

[Rainmeter]
Update=100
DynamicWindowSize=1
MouseOverAction=!SetOption mDay1 FontColor 255,255,255,255
1) MouseLeaveAction=!SetOption mDay1 FontColor #*Txt.Clr*#
2) MouseLeaveAction=!SetOption mDay1 FontColor ""

[Variables]
Txt.Clr=255,255,25,255

[Style]
FontColor=#Txt.Clr#

[mDay1]
Meter=String
MeterStyle=Style
FontSize=15
Text=Hello

The meter will be yellow, driven by the MeterStyle.. Then SetOption will change it to white on MouseOver, by ADDING a new FontColor=255,255,255,255 to the meter in memory. With the first MouseLeaveAction example, it will change that new FontColor setting to the #Txt.Clr# variable, by using the new "escape" chars "*" to send that variable as a literal. In the second MouseLeaveAction example, it just REMOVES the FontColor setting from the meter, which means it reverts to using the FontColor found in the MeterStyle. The results are identical in this example, but one or the other may be more or less appropriate in other cases.


Be careful though, as:

[Rainmeter]
Update=100
DynamicWindowSize=1
MouseOverAction=!SetOption mDay1 FontColor 255,255,255,255
MouseLeaveAction=!SetOption mDay1 FontColor ""

[Variables]
Txt.Clr=255,255,25,255

[mDay1]
Meter=String
1) FontColor=255,255,25,255
2) FontColor=#Txt.Clr#
FontSize=15
Text=Hello

Will in both cases leave the color as 0,0,0,255, as that is the "default" color of a String meter. Remember that using "" with !SetOption REMOVES the setting from the meter entirely.

Note: We are looking at a !ResetOption bang for a future beta, which if possible will add some additional flexibility.