It is currently May 3rd, 2024, 8:56 pm

A basic code problem I've been unable to solve

Get help with creating, editing & fixing problems with skins
ObsoSoSo
Posts: 3
Joined: November 3rd, 2010, 4:02 pm

A basic code problem I've been unable to solve

Post by ObsoSoSo »

Hi Rainmeter community!

I discovered Rainmeter a few days ago and I've been hard at work [see: play] coding some website parsers for various things (I don't want to reveal just what yet, because I'm packaging them together to release for funzies). However, I've been stumbling over some hurdles and haven't been able to find answers in the documentation or a few of the tutorials I've worked through. I hate to bother people with my noobishness, but I get the feeling I can save a ton of time by asking for a few brief explanations rather than spending hours per issue.

So my most relevant problem is the following situation:

Input: p, t, or z (literally)

Desired output: pL.jpg, tL.jpg, or zL.jpg

Essentially, I parse the data 'p' 't' or 'z' from a website, and then wish to display a relative icon. I've gotten this to work to a degree by using a measure to retrieve the data from my parser, modify the input to the relevant icon's file path, and then reference this measure in my image meter's info.
[IconL]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[GetData]
StringIndex=1
Substitute='p':"#SKINSPATH#ObsSkins\Resources\Icons\pL.jpg"

[Image1]
MeasureName=IconL
Meter=IMAGE
X=2
Y=20
However, when I try to have IconL handle the substitution for all 3 conditions (p, t, or z) it appears to enact the substitution multiple times and chop up my path by substituting the substitution.
[IconL]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[GetData]
StringIndex=1
Substitute='p':"#SKINSPATH#ObsSkins\Resources\Icons\pL.jpg",'t':"#SKINSPATH#ObsSkins\Resources\Icons\tL.jpg",'z':"#SKINSPATH#ObsSkins\Resources\Icons\zL.jpg"
This code produces a series of embedded paths: C:\sdasd\asdas\asdasC:\asasd\asdasd\asC:\asdasd...

In most coding languages I'd just handle the input translation with an if statement (my personal crutch) but that doesn't seem applicable here. Am I right? The two best ways I've been able to reason might work are converting the letters to their ASCII values and using substitute in combination with a calc measure to translate without the risk of reoccurring substitution or simply dropping the input straight into the filepath somehow (see hypothetical code below).
[Image1]
MeasureName=Icon1
Meter=Image
ImageName=#SKINSPATH#ObsSkins\Resources\Icons\ %1 L.jpg
X=2
Y=20
So, after all that jabber, my question is basically, "what is the best way to do this?"

Also, can you / how would you convert a character into a number for the purpose of using a rigged CALC as an IF statement (like the enigma weather skin does). Finally, is there anyway to reference a string within a filepath in order to avoid these shenanigans entirely?
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: A basic code problem I've been unable to solve

Post by jsmorley »

Although I may not get all that you are trying to do, it feels like you are working too hard.

Input: p, t, or z (literally)

Desired output: pL.jpg, tL.jpg, or zL.jpg


[Variables]
ImagePath=Images\

[MeasureInput]
Measure=Plugin
Plugin=Plugins\WebParser.dll
URL=file://#CURRENTPATH#TextFile.txt
RegExp="(?siU)<pattern>(.*)</pattern>"
StringIndex=1

[MeterImage]
Meter=Image
ImageName=#ImagePath#[MeasureInput]L.png
DynamicVariables=1
ObsoSoSo
Posts: 3
Joined: November 3rd, 2010, 4:02 pm

Re: A basic code problem I've been unable to solve

Post by ObsoSoSo »

That is how I imagined it should work, but the [variable] isn't read for some reason. Here is my relevant code:
[Variables]
ImagePath=#SKINSPATH#ObsSkins\Resources\Icons\

[IR1]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[GetData]
StringIndex=3

[DR1]
Meter=IMAGE
ImageName=#ImagePath#[IR1]R.jpg
X=2
Y=24
In the log file I'm getting this error:

Unable to load image: C:\Users\#######\Documents\Rainmeter\Skins\ObsSkins\Resources\Icons\R.jpg

However, the 'p' I'm expecting is being collected from the website, as this code illustrates:
[Line2]
Meter=STRING
MeasureName=IR1
x=64
y=10r
FontColor=255,255,255,255
FontSize=9
StringAlign=LEFT
FontFace=Trebuchet MS
Antialias=1
text=%1 and [IR1]

OUTPUT: p and

[Line3]
Meter=STRING
x=64
y=10r
FontColor=255,255,255,255
FontSize=9
StringAlign=LEFT
FontFace=Trebuchet MS
Antialias=1
text=#ImagePath#[IR1]R.jpg

OUTPUT: C:\Users\#######\Documents\Rainmeter\Skins\ObsSkins\Resources\Icons\R.jpg
Is there perhaps a syntax or timing issue that would cause an embedded [variable] to be ignored?
Thanks for helping, by the way.
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: A basic code problem I've been unable to solve

Post by jsmorley »

[MeterImage]
Meter=Image
ImageName=#ImagePath#[MeasureInput]L.png
DynamicVariables=1
ObsoSoSo
Posts: 3
Joined: November 3rd, 2010, 4:02 pm

Re: A basic code problem I've been unable to solve

Post by ObsoSoSo »

:( Ack! I knew I should have copy/pasted your code and modified it instead of just copying it manually. Thank you!!! Sorry I missed that!
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: A basic code problem I've been unable to solve

Post by jsmorley »

ObsoSoSo wrote::( Ack! I knew I should have copy/pasted your code and modified it instead of just copying it manually. Thank you!!! Sorry I missed that!
;-)

No sweat. Hope it's all working for you now. There are several ways to approach what you were trying to do, and I only demonstrated one of them, but I like that approach. While you have to wrap your head around dynamic variables and such a bit more than other ways, it feels clean to me.