LUA GetOption() - How to preserve variable references?
Posted: May 25th, 2019, 12:38 am
I am using the GetOption() function with a meter object in my LUA script. The idea is to get the "Fill" key from a shape so I can create a generalized hover logic for my color picker buttons:
It works perfectly! However, I soon discovered that upon changing the color with my ColorPickerPlus skin (which is what clicking one of these buttons allows you to do), the new color wasn't being represented on the icon without a skin refresh.
After some digging, it turns out that the GetOption() meter function does not preserve variable references. So if I have a meter with Fill=Fill Color #colorCore1#, instead of retrieving that string, the function is retrieving Fill=Fill Color 107,238,98 (being the value of #colorCore1# at that given time).
Is there some method of retrieving a key while preserving the variable references, without resorting to straight-up reading the file with something akin to ReadIni()?
Here is an over-simplified example skin. The button is supposed to turn green when clicked, but since the variable reference is lost, it doesn't:
Hover.ini:
Hover.lua:
It works perfectly! However, I soon discovered that upon changing the color with my ColorPickerPlus skin (which is what clicking one of these buttons allows you to do), the new color wasn't being represented on the icon without a skin refresh.
After some digging, it turns out that the GetOption() meter function does not preserve variable references. So if I have a meter with Fill=Fill Color #colorCore1#, instead of retrieving that string, the function is retrieving Fill=Fill Color 107,238,98 (being the value of #colorCore1# at that given time).
Is there some method of retrieving a key while preserving the variable references, without resorting to straight-up reading the file with something akin to ReadIni()?
Here is an over-simplified example skin. The button is supposed to turn green when clicked, but since the variable reference is lost, it doesn't:
Hover.ini:
Code: Select all
[Rainmeter]
MiddleMouseUpAction=[!Refresh]
AccurateText=1
[Variables]
colorButton=255,50,50
[MeasureScript]
Measure=Script
ScriptFile=#@#Scripts\Hover.lua
[MeterHoverShape]
Meter=Shape
Shape=Rectangle 0,0,25,25,3 | StrokeWidth 0 | Extend Fill
Fill=Fill Color #colorButton#
MouseOverAction=[!SetOption #CURRENTSECTION# Fill "[&MeasureScript:GetKey('[#CURRENTSECTION]', 'Fill')],230"][!UpdateMeter #CURRENTSECTION#][!Redraw]
MouseLeaveAction=[!SetOption #CURRENTSECTION# Fill "[&MeasureScript:Gsub('[&MeasureScript:GetKey('[#CURRENTSECTION]', 'Fill')]',',230')]"][!UpdateMeter #CURRENTSECTION#][!Redraw]
LeftMouseUpAction=[!SetVariable colorButton "50,255,50"][!UpdateMeter #CURRENTSECTION#][!Redraw]
DynamicVariables=1
Code: Select all
function Initialize() end
function Update() end
function GetKey(name, key) return SKIN:GetMeter(name):GetOption(key) end
function Gsub(string, pattern, replacement) return string:gsub(pattern, replacement or '') end