It is currently September 8th, 2024, 4:41 am

Check if variable exists and open skin

Get help with creating, editing & fixing problems with skins
andyroe208
Posts: 13
Joined: September 17th, 2012, 10:39 am

Check if variable exists and open skin

Post by andyroe208 »

I have created 2 skins, the main one of which holds data as required and the other a settings like panel where you will select 1 option only. I am looking at running a quick check in the main to see if a variable is missing or is 0 and if so open the settings window to allow the user to select their option. To me this should be simple but no matter the amount of searching or what I try it does not work.

My latest attempt is as follows

Code: Select all

@include=#@#DriverVariables.inc

[Variables]
Check=#UsedBefore#

IfCondition=#Check# = "0"
IfTrueAction=[!ActivateConfig "GeorgeRussell" "Settings.ini"]
IfFalseAction=
I have looked into this quite a bit over the past few days and saw the IfCondition documentation and figured it would be something similar to the !ActivateConfig statement I used above.

Any help on this would be appreciated and as always I don't expect the full answer, I'm always happy to pointed in the right direction to further my knowledge :)
Last edited by andyroe208 on June 29th, 2024, 4:31 pm, edited 1 time in total.
User avatar
Yincognito
Rainmeter Sage
Posts: 8030
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Check if variable exists and open skin

Post by Yincognito »

First, you should make sure that #Check# / #UsedBefore# is numerical, IfConditions don't work with strings (by the way, you could have just used #UsedBefore# in the comparison, no need to duplicate the variable to #Check#, unless of course you have other plans like changing #Check# while keeping #UsedBefore# unchanged).

Secondly, IfConditions are typically added to a measure, unlike your usage which actually attaches the IfCondition to the [Variables] section. Or, alternatively, just use a Calc measure with Formula=#UsedBefore# and do the comparison on the value of that Calc measure (while adding DynamicVariables=1 to the measure), it's the same thing.

Thirdly, assuming your Config and File parameters in the !ActivateConfig are correct, your code contradicts your description:
if a variable [...] is 0 and if not to open the settings window
considering that in the code you activate the [SkinsFolder]\GeorgeRussell\Settings.ini when the #UsedBefore# (or #Check#, per your duplication) variable is 0 (as opposed to being different than 0, like in your description).

Lastly, not really mandatory, but if you don't want to do anything in one of the IfCondition branches (IfTrueAction or IfFalseAction, doesn't matter), you could just as well remove the said branch altogether.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
andyroe208
Posts: 13
Joined: September 17th, 2012, 10:39 am

Re: Check if variable exists and open skin

Post by andyroe208 »

Thanks for your quick response, I wasn't expecting it on a weekend :)

I can confirm there would only be numeric values, I would have that variable set as 0 initially and then updates to 1 once a selection has been made and these would be the only variable options. As soon as you mentioned the variable I declared I realised I should have stated this was only there to rule out issues not reading from the variable file as expected and this would have been removed once I worked out the bigger issue I am having but thanks for reminding me of it.

I had seen the IfCondition used in measures but thought I may be able to do the check without the need for a measure but if that is the correct way then I understand what is needed to correct that side of things.

Well spotted on the mistake. I triple checked before sending and still got it wrong! It should have been if variable is 0 then open settings so I will update the original post for clarity if possible.

I will remove the code and see how much further I can get with this help. Thanks again :)
User avatar
Yincognito
Rainmeter Sage
Posts: 8030
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Check if variable exists and open skin

Post by Yincognito »

andyroe208 wrote: June 29th, 2024, 1:37 pm Thanks for your quick response, I wasn't expecting it on a weekend :)

I can confirm there would only be numeric values, I would have that variable set as 0 initially and then updates to 1 once a selection has been made and these would be the only variable options. As soon as you mentioned the variable I declared I realised I should have stated this was only there to rule out issues not reading from the variable file as expected and this would have been removed once I worked out the bigger issue I am having but thanks for reminding me of it.

I had seen the IfCondition used in measures but thought I may be able to do the check without the need for a measure but if that is the correct way then I understand what is needed to correct that side of things.

Well spotted on the mistake. I triple checked before sending and still got it wrong! It should have been if variable is 0 then open settings so I will update the original post for clarity if possible.

I will remove the code and see how much further I can get with this help. Thanks again :)
Sure thing. Here's the code with an equivalent Calc measure (this assumes that the UsedBefore variable is declared in one of your @includes, so, given that the variable is presumably also used in Settings.ini, such an @include should be part of both your main skin and the settings one - not sure your DriverVariables.inc does that):

Code: Select all

[Variables]
@include=#@#DriverVariables.inc

[Check]
Measure=Calc
Formula=#UsedBefore#
UpdateDivider=-1
IfCondition=([Check]=0)
IfTrueAction=[!ActivateConfig "GeorgeRussell" "Settings.ini"]
DynamicVariables=1
The above updates [Check] only once, due to its negative UpdateDivider, so it's suited for checking things only when the main skin is loaded or refreshed.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
balala
Rainmeter Sage
Posts: 16499
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Check if variable exists and open skin

Post by balala »

andyroe208 wrote: June 29th, 2024, 12:34 pm I am looking at running a quick check in the main to see if a variable is missing or is 0 and if not
There is a way to check if a variable exists or not and if it does, to check its value and take decision accordingly. Here is the example:

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

[Variables]
Variable=5

[MeasureVariableString]
Measure=STRING
String=#Variable#
IfMatch=#*Variable*#
IfMatchAction=[!SetVariable Result "The variable doesn't exist."][!DisableMeasure "MeasureVariableNum"]
IfNotMatchAction=[!EnableMeasure "MeasureVariableNum"]

[MeasureVariableNum]
Measure=Calc
Formula=#Variable#
IfCondition=(#Variable#=0)
IfTrueAction=[!SetVariable Result "The variable exists. Its value is 0."]
IfFalseAction=[!SetVariable Result "The variable exists. It's greater than 0."]
DynamicVariables=1
Disabled=1

[MeterResult]
Meter=STRING
X=0
Y=0
Padding=15,5,15,5
FontColor=220,220,220
FontEffectColor=0,0,0
StringEffect=Shadow
SolidColor=0,0,0,150
FontSize=8
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
Text=#Result#
DynamicVariables=1
The [MeterResult] shows the result: if the variable exists (has been declared into the [Variables] section), the meters shows either The variable exists. Its value is 0., or The variable exists. It's greater than 0., accordingly to the value of the existing variable. If on the other hand, the variable doesn't exist, the meters shows The variable doesn't exist..
andyroe208
Posts: 13
Joined: September 17th, 2012, 10:39 am

Re: Check if variable exists and open skin

Post by andyroe208 »

Yincognito wrote: June 29th, 2024, 2:08 pm Sure thing. Here's the code with an equivalent Calc measure (this assumes that the UsedBefore variable is declared in one of your @includes, so, given that the variable is presumably also used in Settings.ini, such an @include should be part of both your main skin and the settings one - not sure your DriverVariables.inc does that):

Code: Select all

[Variables]
@include=#@#DriverVariables.inc

[Check]
Measure=Calc
Formula=#UsedBefore#
UpdateDivider=-1
IfCondition=([Check]=0)
IfTrueAction=[!ActivateConfig "GeorgeRussell" "Settings.ini"]
DynamicVariables=1
The above updates [Check] only once, due to its negative UpdateDivider, so it's suited for checking things only when the main skin is loaded or refreshed.
Thanks for the help there. I had just implemented my version which was very similar minus the UpdateDivider=-1. I had also declared DynamicVariables=1 at the top of my file which seems to work but obviously you were not aware of that.

As for variables file, I thought it would be best to have 2 both of which are declared where needed, 1 that holds the driver information and the other for global variables as I will need to be updating the driver information (With lua I think) this way making it easier for myself to try to process any further issues.

1 question on your code though. You used IfCondition=([Check]=0) how does this differ to my usage of IfCondition=#Check# = 0? In the long run I want to make this available to others so would like things to be done correctly :)
User avatar
Yincognito
Rainmeter Sage
Posts: 8030
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Check if variable exists and open skin

Post by Yincognito »

andyroe208 wrote: June 29th, 2024, 4:30 pmI had also declared DynamicVariables=1 at the top of my file
Take into account that DynamicVariables=1, like any other Option=Value pair, is applied only to the [Section] that it belongs to (basically, the first [Section] occurrence before the said pair). So, declaring DynamicVariables=1 at the top of your file will have no effect on the [Sections] after it. In case you were not aware of this, of course.
andyroe208 wrote: June 29th, 2024, 4:30 pmYou used IfCondition=([Check]=0) how does this differ to my usage of IfCondition=#Check# = 0?
Simple, you probably used the value of the variable named Check from your OP code (which is equal to the value of the UsedBefore variable), while I used the value of the measure named Check in my code (which is also equal to the value of the UsedBefore variable, given the Formula option in the [Check] measure). Other than that, the round brackets and the lack of spaces is mostly my preference, with the round brackets helping if I want to add another condition part to the code later on, e.g. IfCondition=([Check]=0) && ([AnotherMeasure]>5) where && means the logical AND.

References:
- https://docs.rainmeter.net/manual/getting-started/skin-anatomy/
- https://docs.rainmeter.net/manual/measures/general-options/ifconditions/#IfCondition
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
andyroe208
Posts: 13
Joined: September 17th, 2012, 10:39 am

Re: Check if variable exists and open skin

Post by andyroe208 »

Ah, thank you for clarifying both of those. Glad I asked the questions now.

I thought declaring at the top like when declaring includes would be fine so I will make that small adjustment.

As for the IfCondition statement explanation that makes sense and I really appreciate your time on doing this. I'm not the smartest person but I also am not clueless but sometimes documentation is not always the clearest for me (no disrespect to Rainmeter for this).

Mental note made on all of this, thank you once again :)
User avatar
Yincognito
Rainmeter Sage
Posts: 8030
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Check if variable exists and open skin

Post by Yincognito »

andyroe208 wrote: June 29th, 2024, 6:52 pm Ah, thank you for clarifying both of those. Glad I asked the questions now.

I thought declaring at the top like when declaring includes would be fine so I will make that small adjustment.

As for the IfCondition statement explanation that makes sense and I really appreciate your time on doing this. I'm not the smartest person but I also am not clueless but sometimes documentation is not always the clearest for me (no disrespect to Rainmeter for this).

Mental note made on all of this, thank you once again :)
Sure thing, you're welcome, hopefully this and other bits from the docs (once you fully understand the basics) will be useful for you going forward. ;-)
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth