It is currently April 19th, 2024, 8:26 am

[HELP] Check if a [section] exists

Discuss the use of Lua in Script measures.
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

[HELP] Check if a [section] exists

Post by smurfier »

Is there any easy way to check if a certain section exists in the skin?
The only way i can imagine to do this is parse through the skin.ini looking for [section].
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: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Check if a [section] exists

Post by jsmorley »

smurfier wrote:Is there any easy way to check if a certain section exists in the skin?
The only way i can imagine to do this is parse through the skin.ini looking for [section].
If you know the name you are looking for, then just:

msIsMeasure = SKIN:GetMeasure("MeasureName")
if not msIsMeasure then print("FUBAR") end

Or even this should work:

if not SKIN:GetMeasure("MeasureName") then print("You were eaten by a grue")
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Check if a [section] exists

Post by smurfier »

Even if I'm checking for a certain Meter Style?
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: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Check if a [section] exists

Post by jsmorley »

smurfier wrote:Even if I'm checking for a certain Meter Style?
No, it will only work with meters and measures. Parse away...

You could always add the MeterStyle name as a variable or as a "setting" on the script measure. Then you could test for it easy enough. I suspect there is some good reason why a script you wrote to go with a skin you wrote doesn't know what is in the skin...
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Check if a [section] exists

Post by smurfier »

fun...

Before I go through all that work, is there any problem with setting MeterStyle to a non-existent style? I tried earlier and Rainmeter froze, but something tells me it wasn't what I was doing at the time.
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: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Check if a [section] exists

Post by jsmorley »

smurfier wrote:fun...

Before I go through all that work, is there any problem with setting MeterStyle to a non-existent style? I tried earlier and Rainmeter froze, but something tells me it wasn't what I was doing at the time.
Not sure what that would do. By the way, another thought occurred to me. A MeterStyle can also be a meter...

[MyStyle]
Meter=String
FontSize=10
FontColor=FFFFFF
X=0
Y=2R

Just don't have it display any actual text of any kind (and preferably don't give it any width or height) and you can then use it as a style in other meters, and test for it from Lua with

if not SKIN:GetMeter("MyStyle") then print("I'm sorry Dave, I can't do that")
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Check if a [section] exists

Post by jsmorley »

One side benefit of doing that is that you can then use "GetOption" from Lua and actually read all the values for the style too.
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Check if a [section] exists

Post by Kaelri »

smurfier wrote:Before I go through all that work, is there any problem with setting MeterStyle to a non-existent style? I tried earlier and Rainmeter froze, but something tells me it wasn't what I was doing at the time.
Looks ok to me. Test skin:

Code: Select all

[Rainmeter]
BackgroundMode=2
SolidColor=0,0,0,128
W=300
H=200

; [MeterStyle1]
; FontSize=25

[MeterStyle2]
FontColor=255,0,0
FontSize=50

[Null]
Meter=String
MeterStyle=MeterStyle1
FontColor=ffffff
Text=Hi
W=300
H=200
LeftMouseUpAction=!SetOption Null MeterStyle "MeterStyle2"
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Check if a [section] exists

Post by smurfier »

I'm working on making LuaCalendar more customizable using MeterStyles. I need to make certain options optional. Also, through my somewhat brief existence I've learned that these things need to be as idiot proof and user friendly as possible.

I believe the easiest approach to my predicament is to have the user pass the names of the optional meterstyles to the script as options.
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: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Check if a [section] exists

Post by jsmorley »

smurfier wrote:I'm working on making LuaCalendar more customizable using MeterStyles. I need to make certain options optional. Also, through my somewhat brief existence I've learned that these things need to be as idiot proof and user friendly as possible.

I believe the easiest approach to my predicament is to have the user pass the names of the optional meterstyles to the script as options.
Certainly the most reliable. Well, at least you can blame them if they mess it up, instead of them blaming you... ;-)