It is currently April 20th, 2024, 7:23 am

[Solved] Help with using variables to call measures

Get help with creating, editing & fixing problems with skins
User avatar
wphyer
Posts: 2
Joined: December 30th, 2016, 5:11 am

[Solved] Help with using variables to call measures

Post by wphyer »

So I've spent way too many hours searching and trying to figure out a problem I've encountered.

I have a Meter that's bound to a Measure. The bound Measure (string) has some conditional logic to set some variable values and then call another Measure to retrieve the final data by using a !SetVariable and then binding the variable to the String= line. But the called measure is returning empty data.

The rundown: The variable "dataType" determines if the data retrieved is going to be from the alpha fields or the numeric fields. If the value is 0 the output should be "1:T1:" and if the value is 1 the output should be "A[RFK]". What I'm seeing is "n/a:T1:" and "n/a[RFK]" respectively.

When troubleshooting, I know I'm getting data because in the [meterDisplayValue] if I set the MeasureName to either optAlpha or optNumeric I get the correct data. Or if in [setFirst] I change the String to [optAlpha] or [optNumeric] I get the data. In both scenarios the extensions would not be correct.

I've gone through a lot of iterations of trying different approaches but I'm stuck. Any help that gets me past this would be incredibly appreciated.

Now, I know the first response would be "Just set the extension variable at the top accordingly." and I would agree with that. Unfortunately, this is just a tiny snippet that isolates my problem of a larger project. I would rather the users just change 1 value instead of very many and potentially display invalid data.

Here's the code:

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
BackgroundMode=2
SolidColor=28,32,92,192
DynamicWindowSize=1

[Metadata]
Name=Test_Snippet
Author=wphyer
Information=Gets alpha and numeric data
License=Creative Commons BY-NC-SA 4.0
Version=0.0.1

[Variables]
;dataType: 0 (alpha) | 1 (numeric)
dataType=1
extension=""
runMeasure=""

[getXmlData]
Measure=Plugin
Plugin=WebParser
Url=http://dns.mostly-harmless.lan/stuff/sample_test.xml
UpdateRate=3600
RegExp=(?siU)<data>(.*)</data>
DynamicVariables=1

[getNumericData]
Measure=Plugin
Plugin=WebParser
URL=[getXmlData]
RegExp=(?siU)<n_val1>(.*)</n_val1>
StringIndex=1
StringIndex2=1
Substitute="":"n/a"
DynamicVariables=1

[getAlphaData]
Measure=Plugin
Plugin=WebParser
URL=[getXmlData]
RegExp=(?siU)<a_val1>(.*)</a_val1>
StringIndex=1
StringIndex2=1
Substitute="":"n/a"
DynamicVariables=1

[optAlpha]
Measure=String
String=[getAlphaData]
DynamicVariables=1

[optNumeric]
Measure=String
String=[getNumericData]
DynamicVariables=1

[setFirst]
Measure=String
IfCondition=#dataType# = 0
IfTrueAction=[!SetVariable extension ":T1:"] [!SetVariable runMeasure "[optAlpha]"]
IfCondition2=#dataType# = 1
IfTrueAction2=[!SetVariable extension "[RFK]"] [!SetVariable runMeasure "[optNumeric]"]
String=#runMeasure#
DynamicVariables=1

[styleCommon]
StringCase=None
StringStyle=Normal
StringEffect=Shadow
FontFace=Arial
AntiAlias=1
ClipString=0
StringAlign=Left
FontColor=230,230,230,255
FontSize=9

[meterDisplayValue]
Meter=String
MeterStyle=styleCommon
MeasureName=setFirst
x=0
Y=0
Text=%1#extension#
DynamicVariables=1
A sample of the XML that could be used for testing:

Code: Select all

<data><a_val1>A</a_val1><n_val1>1</n_val1></data>
Last edited by wphyer on December 30th, 2016, 10:57 pm, edited 1 time in total.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5398
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Help with using variables to call measures

Post by eclectic-tech »

Add IfConditionMode=1 to the [setFirst] measure code:

Code: Select all

[setFirst]
Measure=String
String=#runMeasure#
IfCondition=#dataType# = 0
IfTrueAction=[!SetVariable extension ":T1:"] [!SetVariable runMeasure "[optAlpha]"]
IfCondition2=#dataType# = 1
IfTrueAction2=[!SetVariable extension "[RFK]"] [!SetVariable runMeasure "[optNumeric]"]
IfConditionMode=1
DynamicVariables=1
This will test on every skin update. You will see 'n/a' with the extension until the webparser reads the site, then it will change to the returned value '1[RFK]' or 'A:T1:'.
User avatar
wphyer
Posts: 2
Joined: December 30th, 2016, 5:11 am

Re: Help with using variables to call measures

Post by wphyer »

You're awesome. Thank you so much for showing me the solution. You have no idea how happy little things like this make me. :D
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5398
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Help with using variables to call measures

Post by eclectic-tech »

wphyer wrote:You're awesome. Thank you so much for showing me the solution. You have no idea how happy little things like this make me. :D
Happy to help. :welcome: