It is currently March 29th, 2024, 12:44 am

Lua SetH() and SetW() functions not working

Report bugs with the Rainmeter application and suggest features.
rabra
Posts: 11
Joined: October 2nd, 2016, 3:59 am

Lua SetH() and SetW() functions not working

Post by rabra »

Hi,

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.

Code: Select all

MyMeter:SetH(200) - not working
SKIN:Bang('[!SetOption "MyMeter" "H" "'.. 200 ..'"]') - works just fine.
Rainmeter 4.1.0 beta r2858 64-bit (Aug 24 2017)

Any suggestions?
Best regards.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Lua SetH() and SetW() functions not working

Post by jsmorley »

rabra wrote:Hi,

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.

Code: Select all

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:

Initialize()
myMeterObject = SKIN:GetMeter('MyMeter')

Update()
myMeterObject:SetH(200)

I would just use the bang myself...
rabra
Posts: 11
Joined: October 2nd, 2016, 3:59 am

Re: Lua SetH() and SetW() functions not working

Post by rabra »

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:

Initialize()
myMeterObject = SKIN:GetMeter('MyMeter')

Update()
myMeterObject:SetH(200)

I would just use the bang myself...
Thank you jsmorley for quick answer.

My idea was to set-up meter position and size on skin load or refresh using values stored in variables or acording to some condition.

Example:

Code: Select all

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.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Lua SetH() and SetW() functions not working

Post by jsmorley »

rabra wrote:Thank you jsmorley for quick answer.

My idea was to set-up meter position and size on skin load or refresh using values stored in variables or acording to some condition.

Example:

Code: Select all

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.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Lua SetH() and SetW() functions not working

Post by jsmorley »

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.

Also, I think you will want:

SKIN:Bang('!UpdateMeter', '*')
SKIN:Bang('!Redraw')

At the end of your Lua function, so there is no "lag" before the next regular skin update and redraw happens.