It is currently July 13th, 2024, 10:10 pm

WebParser measure not being seen by IfCondition command

Get help with creating, editing & fixing problems with skins
CoffeeBender
Posts: 6
Joined: September 16th, 2023, 11:40 am

WebParser measure not being seen by IfCondition command

Post by CoffeeBender »

I can't use the string from an WebParser measure on the IfCondition statement, I can't really tell what is happening so here is the code

Code: Select all

[Variables]
CharLynette=10000083

[MeasurePfp]
Measure=WebParser
Url=[MeasureSite]
StringIndex=5

[MeasureCondition]
Measure=String
DynamicVariables=1
IfCondition=(#CharLynette# = [MeasurePfp])
IfTrueAction=[!SetOption MeasureDownloadPfpImg Url "https://enka.network/ui/UI_AvatarIcon_Linette.png"]

[MeasureDownloadPfpImg]
Measure=WebParser
URL=
Download=1
Everything is working and it even downloads the image if I hardcode the part where [MeasurePfp] are to 10000083 to match the Variable #CharLynette# but when I use [MeasurePfp](it also have values 10000083) it does not work anymore
Last edited by balala on September 16th, 2023, 12:01 pm, edited 1 time in total.
Reason: Please use <code> tags whenever are posting codes. It's the </> button.
User avatar
balala
Rainmeter Sage
Posts: 16389
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: WebParser measure not being seen by IfCondition command

Post by balala »

CoffeeBender wrote: September 16th, 2023, 11:49 am I can't use the string from an WebParser measure on the IfCondition statement, I can't really tell what is happening so here is the code
No, in fact this is not a functional code, we can't try it out, because there are missing many things (the [MeasureSite] parent WebParser measure, or at least the URL, for instance). But try adding a DynamicVariables=1 option to the [MeasureCondition] measure. This is needed because the [MeasurePfp] element used into the IfCondition option is a section variable, which requires to set the dynamic variables, otherwise Rainmeter can't use them.
If this doesn't help, post a more or less full code, in which the WebParser measures work, to can check.
CoffeeBender
Posts: 6
Joined: September 16th, 2023, 11:40 am

Re: WebParser measure not being seen by IfCondition command

Post by CoffeeBender »

balala wrote: September 16th, 2023, 12:07 pm No, in fact this is not a functional code, we can't try it out, because there are missing many things (the [MeasureSite] parent WebParser measure, or at least the URL, for instance). But try adding a DynamicVariables=1 option to the [MeasureCondition] measure. This is needed because the [MeasurePfp] element used into the IfCondition option is a section variable, which requires to set the dynamic variables, otherwise Rainmeter can't use them.
If this doesn't help, post a more or less full code, in which the WebParser measures work, to can check.
Oh, Here is the code code where the issue is concerned

Code: Select all

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

[MeasureSite]
Measure=WebParser
URL=https://enka.network/api/uid/814702936
RegExp=(?siU){"playerInfo":.*{"nickname":"(.*)".*"level":(.*),.*"signature":"(.*)".*"worldLevel":(.*),.*"profilePicture":{"avatarId":(.*)}}.*"uid":"(.*)"}
Update=3200

[MeasurePfp] ;Takes the Player's Profile picture's ID
Measure=WebParser
Url=[MeasureSite]
StringIndex=5

[MeterDownloadPfpImg] ;For Downloading The Profile Picture
Meter=Image
MeasureName=MeasureDownloadPfpImg
X=10
Y=10
H=100
W=100

[MeasureCondition]
Measure=String
IfCondition=(10000083=[MeasurePfp])
IfTrueAction=[!SetOption MeasureDownloadPfpImg Url "https://enka.network/ui/UI_AvatarIcon_Linette.png"]
DynamicVariables=1

[MeasureDownloadPfpImg]
Measure=WebParser
URL=
Download=1
Last edited by CoffeeBender on September 16th, 2023, 12:19 pm, edited 1 time in total.
CoffeeBender
Posts: 6
Joined: September 16th, 2023, 11:40 am

Re: WebParser measure not being seen by IfCondition command

Post by CoffeeBender »

Here is the full code, I just started making skins so if I have some parts where things are unnecessarily complicated, feel free to educate me

Code: Select all

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

[MeasureSite]
Measure=WebParser
URL=https://enka.network/api/uid/814702936
RegExp=(?siU){"playerInfo":.*{"nickname":"(.*)".*"level":(.*),.*"signature":"(.*)".*"worldLevel":(.*),.*"profilePicture":{"avatarId":(.*)}}.*"uid":"(.*)"}
Update=3200

;=========================[Player Profile Meausre]====================

[MeasureIgn] ;Takes the Player's IGN
Measure=WebParser
Url=[MeasureSite]
StringIndex=1

[MeasureAR] ;Takes the Player's Adventure Rank
Measure=WebParser
Url=[MeasureSite]
StringIndex=2

[MeasureSign] ;Takes the Player's Signature
Measure=WebParser
Url=[MeasureSite]
StringIndex=3

[MeasureWL] ;Takes the Player's World Level
Measure=WebParser
Url=[MeasureSite]
StringIndex=4

[MeasurePfp] ;Takes the Player's Profile picture's ID
Measure=WebParser
Url=[MeasureSite]
StringIndex=5

[MeasureUID] ;Takes the Player's UID
Measure=WebParser
Url=[MeasureSite]
StringIndex=6

;=========================[Player Profile Meters]====================

[MeterProfileBackground] ;Profile Background
Meter=Image
W=320
H=150
SolidColor=20,20,20,127 

[MeterPfp] ;Profile picture Background
Meter=Shape
Shape=Rectangle 10,10,100,100 | Fill Color 20,20,20,127 | StrokeWidth 0
Hidden=0

[MeterUid] ;Player UID
Meter=String
MeasureName=MeasureUid
X=60
Y=5R
FontFace=HYWenHei-85W
FontSize=11
FontColor=252,251,202,255
Padding=5,5,5,5
StringAlign=Center
AntiAlias=1

[MeterIgn] ;Player In Game Name(IGN)
Meter=String
MeasureName=MeasureIgn
X=115
Y=20
FontFace=HYWenHei-85W
FontSize=20
FontColor=252,251,202,255
Padding=5,5,5,5
StringAlign=Left
AntiAlias=1

[MeterARLabel] ;"AR" Label
Meter=String
X=115
Y=60
FontFace=HYWenHei-85W
FontSize=11
FontColor=252,251,202,255
Padding=5,5,5,5
StringAlign=Left
AntiAlias=1
Text=AR

[MeterAR] ;PLayer Adventure Rank
Meter=String
MeasureName=MeasureAR
X=0R
Y=60
FontFace=HYWenHei-85W
FontSize=11
FontColor=252,251,202,255
Padding=5,5,5,5
StringAlign=Left
AntiAlias=1

[MeterWLLabel] ;"WL" Label
Meter=String
X=0R
Y=60
FontFace=HYWenHei-85W
FontSize=11
FontColor=252,251,202,255
Padding=5,5,5,5
StringAlign=Left
AntiAlias=1
Text=-  WL

[MeterWL] ;Player World Level
Meter=String
MeasureName=MeasureWL
X=0R
Y=60
FontFace=HYWenHei-85W
FontSize=11
FontColor=252,251,202,255
Padding=5,5,5,5
StringAlign=Left
AntiAlias=1

[MeterSign] ;Player Signature
Meter=String
MeasureName=MeasureSign
X=115
Y=90
FontFace=HYWenHei-85W
FontSize=11
FontColor=252,251,202,200
Padding=5,5,5,5
StringAlign=Left
AntiAlias=1

;====================[Image Download]====================

[MeterDownloadPfpImg] ;For Downloading The Profile Picture
Meter=Image
MeasureName=MeasureDownloadPfpImg
X=10
Y=10
H=100
W=100

[MeasureCondition]
Measure=String
IfCondition=(10000083=[MeasurePfp])
IfTrueAction=[!SetOption MeasureDownloadPfpImg Url "https://enka.network/ui/UI_AvatarIcon_Linette.png"]
DynamicVariables=1

[MeasureDownloadPfpImg]
Measure=WebParser
URL=
Download=1
User avatar
balala
Rainmeter Sage
Posts: 16389
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: WebParser measure not being seen by IfCondition command

Post by balala »

CoffeeBender wrote: September 16th, 2023, 12:18 pm Here is the full code, I just started making skins so if I have some parts where things are unnecessarily complicated, feel free to educate me
Seeing the whole code it became extremely clear what is wrong.
The [MeasureDownloadPfpImg] measure (which should download the image) gets the URL only when you get executed the IfTrueAction option of the [MeasureCondition] measure, this URL option being set by the IfTrueAction option. But this IfTrueAction option can be executed only when the WebParser measures (here strictly it's about the [MeasurePfp] measure, which is used into the IfCondition) get their values. But since all WebParser measures (namely the [MeasurePfp] measure) need time to get the value, when you load the skin, the [MeasurePfp] measure gets a value after let's say two - three seconds. But when this goes on and the [MeasureDownloadPfpImg] measure gets its URL, it has been updated with no URL (this leads to an error message in the Log), and you have to wait 10 minutes (the default time) until the next update. If you wait so long, you get the image downloaded, but this obviously is not a proper solution. So we have to ask the [MeasureDownloadPfpImg] measure to update right when it gets the URL. This can be done by adding a [!CommandMeasure "MeasureDownloadPfpImg" "Update"] bang to the IfTrueAction option of the [MeasureCondition] measure. This way, when you get executed the IfTrueAction option, the [MeasureDownloadPfpImg] measure gets its URL and immediately updates.

Additional improvement: as said above in some cases you get error messages in the Log, this being caused by the fact that some options are not explicitly set, being set only after a while. To fix this I probably would add a Disabled=1 option to the [MeasureDownloadPfpImg] measure (this way getting it disabled), and would enable it when it has to be updated as well, as described above. By this the [MeasureCondition] and [MeasureDownloadPfpImg] measure should look this way:

Code: Select all

[MeasureCondition]
Measure=String
IfCondition=(10000083=[MeasurePfp])
IfTrueAction=[!SetOption MeasureDownloadPfpImg Url "https://enka.network/ui/UI_AvatarIcon_Linette.png"][!EnableMeasure "MeasureDownloadPfpImg"][!CommandMeasure "MeasureDownloadPfpImg" "Update"]
DynamicVariables=1
Disabled=1

[MeasureDownloadPfpImg]
Measure=WebParser
Download=1
Disabled=1
Note that beside the [MeasureDownloadPfpImg] measure, I disabled the [MeasureCondition] measure as well, because otherwise, since the [MeasurePfp] measure has no yet a value when you refresh the skin either, you get another error message in Log. By disabling this measure, its IfCondition is not executed, so you get no URL for the [MeasureDownloadPfpImg] measure. To enable the measure, add a FinishAction=[!EnableMeasure "MeasureCondition"][!UpdateMeasure "MeasureCondition"] option to the [MeasureSite] measure. Thi soption is executed when the measure finishes parsing the source. In this moment the WebParser measures get values and all further measures can execute properly, with no error messages.
Just in case you couldn't deal with all this, here is the full and altered code:

Code: Select all

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

[MeasureSite]
Measure=WebParser
URL=https://enka.network/api/uid/814702936
RegExp=(?siU){"playerInfo":.*{"nickname":"(.*)".*"level":(.*),.*"signature":"(.*)".*"worldLevel":(.*),.*"profilePicture":{"avatarId":(.*)}}.*"uid":"(.*)"}
Update=3200
FinishAction=[!EnableMeasure "MeasureCondition"][!UpdateMeasure "MeasureCondition"]

;=========================[Player Profile Meausre]====================

[MeasureIgn]
;Takes the Player's IGN
Measure=WebParser
Url=[MeasureSite]
StringIndex=1

[MeasureAR]
;Takes the Player's Adventure Rank
Measure=WebParser
Url=[MeasureSite]
StringIndex=2

[MeasureSign]
;Takes the Player's Signature
Measure=WebParser
Url=[MeasureSite]
StringIndex=3

[MeasureWL]
;Takes the Player's World Level
Measure=WebParser
Url=[MeasureSite]
StringIndex=4

[MeasurePfp]
;Takes the Player's Profile picture's ID
Measure=WebParser
Url=[MeasureSite]
StringIndex=5

[MeasureUID]
;Takes the Player's UID
Measure=WebParser
Url=[MeasureSite]
StringIndex=6

;=========================[Player Profile Meters]====================

[MeterProfileBackground]
;Profile Background
Meter=Image
W=320
H=150
SolidColor=20,20,20,127 

[MeterPfp]
;Profile picture Background
Meter=Shape
Shape=Rectangle 10,10,100,100 | Fill Color 20,20,20,127 | StrokeWidth 0
Hidden=0

[MeterUid]
;Player UID
Meter=String
MeasureName=MeasureUid
X=60
Y=5R
FontFace=HYWenHei-85W
FontSize=11
FontColor=252,251,202,255
Padding=5,5,5,5
StringAlign=Center
AntiAlias=1

[MeterIgn]
;Player In Game Name(IGN)
Meter=String
MeasureName=MeasureIgn
X=115
Y=20
FontFace=HYWenHei-85W
FontSize=20
FontColor=252,251,202,255
Padding=5,5,5,5
StringAlign=Left
AntiAlias=1

[MeterARLabel]
;"AR" Label
Meter=String
X=115
Y=60
FontFace=HYWenHei-85W
FontSize=11
FontColor=252,251,202,255
Padding=5,5,5,5
StringAlign=Left
AntiAlias=1
Text=AR

[MeterAR]
;PLayer Adventure Rank
Meter=String
MeasureName=MeasureAR
X=0R
Y=60
FontFace=HYWenHei-85W
FontSize=11
FontColor=252,251,202,255
Padding=5,5,5,5
StringAlign=Left
AntiAlias=1

[MeterWLLabel]
;"WL" Label
Meter=String
X=0R
Y=60
FontFace=HYWenHei-85W
FontSize=11
FontColor=252,251,202,255
Padding=5,5,5,5
StringAlign=Left
AntiAlias=1
Text=-  WL

[MeterWL]
;Player World Level
Meter=String
MeasureName=MeasureWL
X=0R
Y=60
FontFace=HYWenHei-85W
FontSize=11
FontColor=252,251,202,255
Padding=5,5,5,5
StringAlign=Left
AntiAlias=1

[MeterSign]
;Player Signature
Meter=String
MeasureName=MeasureSign
X=115
Y=90
FontFace=HYWenHei-85W
FontSize=11
FontColor=252,251,202,200
Padding=5,5,5,5
StringAlign=Left
AntiAlias=1

;====================[Image Download]====================

[MeterDownloadPfpImg]
;For Downloading The Profile Picture
Meter=Image
MeasureName=MeasureDownloadPfpImg
X=10
Y=10
H=100
W=100

[MeasureCondition]
Measure=String
IfCondition=(10000083=[MeasurePfp])
IfTrueAction=[!SetOption MeasureDownloadPfpImg Url "https://enka.network/ui/UI_AvatarIcon_Linette.png"][!EnableMeasure "MeasureDownloadPfpImg"][!CommandMeasure "MeasureDownloadPfpImg" "Update"]
DynamicVariables=1
Disabled=1

[MeasureDownloadPfpImg]
Measure=WebParser
Download=1
Disabled=1
Note one more: Rainmeter is not a programming language and as such, the comments (unlike in any real programming language) have to be added into new lines. If you want to add a comment, the comment has to be the only thing of the line. Comments after and options or section names are not alowed. This is why in the above code I moved all comments into new lines. You have some details here.
CoffeeBender
Posts: 6
Joined: September 16th, 2023, 11:40 am

Re: WebParser measure not being seen by IfCondition command

Post by CoffeeBender »

balala wrote: September 16th, 2023, 1:16 pm Seeing the whole code it became extremely clear what is wrong.
The [MeasureDownloadPfpImg] measure (which should download the image) gets the URL only when you get executed the IfTrueAction option of the [MeasureCondition] measure, this URL option being set by the IfTrueAction option. But this IfTrueAction option can be executed only when the WebParser measures (here strictly it's about the [MeasurePfp] measure, which is used into the IfCondition) get their values. But since all WebParser measures (namely the [MeasurePfp] measure) need time to get the value, when you load the skin, the [MeasurePfp] measure gets a value after let's say two - three seconds. But when this goes on and the [MeasureDownloadPfpImg] measure gets its URL, it has been updated with no URL (this leads to an error message in the Log), and you have to wait 10 minutes (the default time) until the next update. If you wait so long, you get the image downloaded, but this obviously is not a proper solution. So we have to ask the [MeasureDownloadPfpImg] measure to update right when it gets the URL. This can be done by adding a [!CommandMeasure "MeasureDownloadPfpImg" "Update"] bang to the IfTrueAction option of the [MeasureCondition] measure. This way, when you get executed the IfTrueAction option, the [MeasureDownloadPfpImg] measure gets its URL and immediately updates.
Oh my thank you, so it is not that it's not reading the webparser measure but it was a loading issue, I see, Thank you again this is a life saver
CoffeeBender
Posts: 6
Joined: September 16th, 2023, 11:40 am

Re: WebParser measure not being seen by IfCondition command

Post by CoffeeBender »

now all I need is to repeat this step for every character existing and edit it manually every new character release. I don't know if there is an easier way than this but all I want for now is to be able to do this and learn from more projects to come

again thank you, I will keep the things you said in mind
User avatar
balala
Rainmeter Sage
Posts: 16389
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: WebParser measure not being seen by IfCondition command

Post by balala »

CoffeeBender wrote: September 16th, 2023, 1:49 pm now all I need is to repeat this step for every character existing and edit it manually every new character release. I don't know if there is an easier way than this but all I want for now is to be able to do this and learn from more projects to come
No, actually there is not. You have to edit manually the code. But if you really want to learn, this is the best way to do.
Good luck and feel free to come back if any further question arises. I'm glad if you got it working as expected.
User avatar
Yincognito
Rainmeter Sage
Posts: 7720
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: WebParser measure not being seen by IfCondition command

Post by Yincognito »

balala wrote: September 16th, 2023, 2:47 pm No, actually there is not. You have to edit manually the code. But if you really want to learn, this is the best way to do.
Good luck and feel free to come back if any further question arises. I'm glad if you got it working as expected.
I beg to differ. A list of characters / IDs surely exists somewhere on that site, and even if it's continuously changing, a single WebParser can be commanded to sequentially update and iterate through every ID in that list to get the desired ID data.

Sure, a bit of regex and some quantifiers would be needed if the list is a single string and not values that can be retrieved via StringIndex when interrogating for the list, but it's definitely possible, using dynamic variables in the URL used to get the data for an ID.

Basically, two WebParser parents (one for getting the ID list, one for getting the ID data) with the latter being dynamic should do. Even if Rainmeter is not a programming language, it can do a fair amount of what such a language does. When it doesn't, well, there is always Lua which can fill in the blanks. Not exactly a beginner job, of course, yet still achievable in a nearly automated fashion. ;-)
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
balala
Rainmeter Sage
Posts: 16389
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: WebParser measure not being seen by IfCondition command

Post by balala »

Yincognito wrote: September 16th, 2023, 8:13 pm I beg to differ. A list of characters / IDs surely exists somewhere on that site, and even if it's continuously changing, a single WebParser can be commanded to sequentially update and iterate through every ID in that list to get the desired ID data.

Sure, a bit of regex and some quantifiers would be needed if the list is a single string and not values that can be retrieved via StringIndex when interrogating for the list, but it's definitely possible, using dynamic variables in the URL used to get the data for an ID.

Basically, two WebParser parents (one for getting the ID list, one for getting the ID data) with the latter being dynamic should do. Even if Rainmeter is not a programming language, it can do a fair amount of what such a language does. When it doesn't, well, there is always Lua which can fill in the blanks. Not exactly a beginner job, of course, yet still achievable in a nearly automated fashion. ;-)
Maybe I misunderstood OP's question / comment, but I was talking about the fact that if you wants further measures to get information and image of further characters, the appropriate measures have to be added manually.
Sorry if misunderstood...