It is currently March 29th, 2024, 8:05 am

Accessing a bar meter

Discuss the use of Lua in Script measures.
d00b
Posts: 5
Joined: September 21st, 2011, 10:39 pm

Accessing a bar meter

Post by d00b »

I have a script parsing a web feed via the WebParser plugin and populating skin variables used by string meters.
How can I manipulate a bar meter from the same script?

The only way I can think of is to set the skin variables from the main script, by calling Bang functions, read those in subsidiary scripts and have the bar meters connected to those script measures. It seems a bit superfluous.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Accessing a bar meter

Post by jsmorley »

What do you mean "manipulate a bar meter"? It's not clear what you want to do.

You can set any option except MeasureName= on a Bar meter by using SKIN:Bang('!SetOption MeterName OptionName OptionValue') in the Lua. If you want to set the actual values the Bar meter is using, you will need to either directly use the value returned by WebParser:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[WebMeasure]
Measure=Plugin
Plugin=WebParser.dll
URL=file://#CURRENTPATH#test.txt
RegExp="(?siU)<test>(.*)</test>"
StringIndex=1
UpdateRate=-1
MinValue=0
MaxValue=100

[Back]
Meter=Image
SolidColor=0,0,0,255
W=100
H=20

[Bar]
Meter=BAR
MeasureName=WebMeasure
BarOrientation=Horizontal
W=100
H=20
9-21-2011 7-33-07 PM.jpg
Or if you want to set the the value from Lua for some reason, you could use !SetOption to set the value of a Calc measure to your desired result, then use that Calc measure as the MeasureName= for the Bar meter.

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[MeasureLua]
Measure=Script
ScriptFile="#CURRENTPATH#test.lua"
UpdateDivider=600

[MeasureBarValue]
Measure=Calc
Formula=0
MinValue=0
MaxValue=100

[Back]
Meter=Image
SolidColor=0,0,0,255
W=100
H=20

[Bar]
Meter=BAR
MeasureName=MeasureBarValue
BarOrientation=Horizontal
W=100
H=20

Code: Select all

function Update()

SKIN:Bang("!SetOption MeasureBarValue Formula 32")

end -- function Update
9-21-2011 7-33-07 PM.jpg
You do not have the required permissions to view the files attached to this post.
d00b
Posts: 5
Joined: September 21st, 2011, 10:39 pm

Re: Accessing a bar meter

Post by d00b »

Thank you JS for your swift and detailed reply. Your second example worked a charm. I knew you could use the Lua function return value, but since I wanted to set the values for several Bar meters from the same script, it was not an option. (I suppose you can't have the Lua script return a table/array and use something like StringIndex or %1, %2...?).
I actually did try using a Calc measure as a middle man but by setting Formula to a variable which I in turn had the Lua script putting values into by calling the !SetVariable bang from the script. For some reason I couldn't get that to work (Now that I think of it, I might have forgot to set the DynamicVariables property).

Anyways, cheers a lot for your help and thanks for a most excellent program!
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Accessing a bar meter

Post by jsmorley »

Glad to help. No, there is no way to use Lua "return values" like WebParser does with StringIndex. In a perfect world that might be a nice feature, but not available today. Each script measure creates its own "instance" of Lua even if using the same .lua file, and there is no way to have a second script measure access some value from a table create by the first. It would be inefficient in the extreme to have multiple instances of Lua / .lua running just to "return" different results.