when I try setting width or height of the meter in Lua script using functions SetH() and SetW() nothing happens. Sending bangs through SKIN object works fine.
when I try setting width or height of the meter in Lua script using functions SetH() and SetW() nothing happens. Sending bangs through SKIN object works fine.
MyMeter:SetH(200) - not working
SKIN:Bang('[!SetOption "MyMeter" "H" "'.. 200 ..'"]') - works just fine.
Any suggestions?
Best regards.
SKIN:Bang('!SetOption', 'MyMeter', 'H', '200') is simpler I think.
As far as SetH(200), are you sure you are getting a meter object handle properly first, and setting that? You can't just directly set [MyMeter] in the skin, you need to do something like:
jsmorley wrote:SKIN:Bang('!SetOption', 'MyMeter', 'H', '200') is simpler I think.
As far as SetH(200), are you sure you are getting a meter object handle properly first, and setting that? You can't just directly set [MyMeter] in the skin, you need to do something like:
function Initialize()
metMyMeter = SKIN:GetMeter('MyMeter')
varMyMeterW = MyMeter:GetW()
if (varMyMeterW < 100) then
...
metMyMeter:SetH(200)
...
end
end
I am using functions SetX() and SetY() and they work just fine. So for code consistency, do you suggest using SetX() and SetY() functions or passing bangs through SKIN object?
function Initialize()
metMyMeter = SKIN:GetMeter('MyMeter')
varMyMeterW = MyMeter:GetW()
if (varMyMeterW < 100) then
...
metMyMeter:SetH(200)
...
end
end
I am using functions SetX() and SetY() and they work just fine. So for code consistency, do you suggest using SetX() and SetY() functions or passing bangs through SKIN object?
All best.
I would personally not use Get or Set at all, just SKIN:GetVariable('[MyMeter:W]') and SKIN:Bang('!SetOption', 'MyMeter', 'W', '200')
I can't see any reason to create meter objects at all. Measure objects are needed to get measure "values", but for meters, I'd just use bangs.
Actually, to get the width of a meter you would use:
myW = SKIN:ReplaceVariables('[MyMeter:W]')
You need to use ReplaceVariables and not GetVariable to get the current value of a meter [SectionVariable].
However, I'm very concerned about doing this in Initialize() in Lua.
Meters will not have been updated the first time when Initialize() is run, and they won't have any dynamic width that is based on the value they are using, including any MeasureName on a String meter, or image dynamically used in an Image meter with MeasureName.
Only if the meter has a hard-coded W (and H, X, Y) will those be correct at that point. The meters will have been "created", but not yet "updated".
I think you are going to want to take a different approach. This would involve putting the Lua needed to get and set meter sizes and positions into a stand-alone myFunction() of some kind in the Lua, and calling that function with !CommandMeasure in an OnRefreshAction in the [Rainmeter] section of the skin. OnRefreshAction is executed once at the "end" of the first update cycle, and everything will be in place.