It is currently April 24th, 2024, 9:07 pm

Formula in MeasureName

Get help with creating, editing & fixing problems with skins
User avatar
Missing
Posts: 11
Joined: July 28th, 2022, 8:28 pm

Formula in MeasureName

Post by Missing »

Hello this is a very simple question, I was wondering if there was a way to make the example bellow work.

Code: Select all

[MeterGame1Image]
Meter=Image
MeasureName=MeasureImage(1+#ScrollPos#)Download
X=0
Y=0
MouseScrollDownAction=[!SetVariable ScrollPos "((#ScrollPos#=0)?0:(#ScrollPos#-1))"][!Redraw][!UpdateMeter *]
MouseScrollUpAction=[!SetVariable ScrollPos "((#ScrollPos#=10)?10:(#ScrollPos#+1))"][!Redraw][!UpdateMeter *]
DynamicVariables=1
Obviously it isn't working but I was wondering if there were a way to addition the value of the variable ScrollPos to the number inside the Measure name MeasureImage1Download.

Thank you! :D
Last edited by Missing on March 20th, 2023, 1:29 pm, edited 1 time in total.
User avatar
balala
Rainmeter Sage
Posts: 16168
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Formula in MeasureName

Post by balala »

Missing wrote: March 19th, 2023, 6:48 pm I was wondering if there was a way to make the example bellow work.
There is in fact, however not the way you tried.
As you saw, you can't use formulas in the MeasureName option, especially not one which is altered "on the fly". So we need another approach. Here is one.
You need a measure which gets the value of the variable and converts this value into the name of the appropriate measure. Add the following measure to your code:

Code: Select all

[MeasureScrollPos]
Measure=Calc
Formula=#ScrollPos#
RegExpSubstitute=1
Substitute="^(\d{1,2})$":"MeasureImage\1Download"
DynamicVariables=1
This measure is getting the ScrollPos variable and adds MeasureImage in front of it and Download after. This way the string value of this measure is the name of the measure which has to be used into the MeasureName option of the [MeterGame1Image] meter.
Modify the above mentioned MeasureName option of the [MeterGame1Image] meter to: MeasureName=[MeasureScrollPos] (and if anyone askes, no, the brackets are not mistake, they have to be there, to let the option to use the string - or substituted - value of the measure).
In order to get the whole scrolling working smoother, you can add a [!UpdateMeasure "MeasureScrollPos"] bang to the MouseScrollDownAction and MouseScrollUpAction options of the [MeterGame1Image] meter.

Additional tip: to don't complicate things too much, I'd replace the formulas used into the !SetVariable bangs of the MeasureScrollDownAction and MeasureScrollUpAction options of the [MeterGame1Image] meter, using the Clamp function. With all the above additions, the meter should look this way:

Code: Select all

[MeterGame1Image]
Meter=Image
MeasureName=[MeasureScrollPos]
X=0
Y=0
MouseScrollDownAction=[!SetVariable ScrollPos "(Clamp((#ScrollPos#-1),0,10))"][!UpdateMeasure "MeasureScrollPos"][!UpdateMeter *][!Redraw]
MouseScrollUpAction=[!SetVariable ScrollPos "(Clamp((#ScrollPos#+1),0,10))"][!UpdateMeasure "MeasureScrollPos"][!UpdateMeter *][!Redraw]
DynamicVariables=1
User avatar
Yincognito
Rainmeter Sage
Posts: 7157
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Formula in MeasureName

Post by Yincognito »

Missing wrote: March 19th, 2023, 6:48 pm Hello this is a very simple question, I was wondering if there was a way to make the example bellow work.

Code: Select all

[MeterGame1Image]
Meter=Image
MeasureName=MeasureImage(1+#ScrollPos#)Download
X=0
Y=0
MouseScrollDownAction=[!SetVariable ScrollPos "((#ScrollPos#=0)?0:(#ScrollPos#-1))"][!Redraw][!UpdateMeter *]
MouseScrollUpAction=[!SetVariable ScrollPos "((#ScrollPos#=10)?10:(#ScrollPos#+1))"][!Redraw][!UpdateMeter *]
DynamicVariables=1
Obviously it isn't working but I was wondering if there were a way to addition the value of the variable ScrollPos to the number inside the Measure name MeasureImage1Download.

Thank you! :D
What I don't understand here is why you want to change the value after MeasureImage inside the MeasureName option, since you can easily change it in your mouse actions, any other bang, or even in a Calc measure (in fact, you already do this in your mouse actions). The only reason I could think of for that is if you somehow want to begin at 1 instead of 0 or something similar. I would write this like this instead:

Code: Select all

[MeterGame1Image]
Meter=Image
MeasureName=MeasureImage#ScrollPos#Download
MouseScrollDownAction=[!SetVariable ScrollPos ((10+#ScrollPos#-1)%10)][!UpdateMeter *][!Redraw]
MouseScrollUpAction=[!SetVariable ScrollPos ((10+#ScrollPos#+1)%10)][!UpdateMeter *][!Redraw]
DynamicVariables=1
This, of course, assumes that your MeasureImageNDownload (where N ranges from 0 to 9) measures produce strings that represent valid paths to your images, and that you initialized the ScrollPos variable to some value beforehand in your skin. If you wonder, the formulas in the mouse actions are an alternative to the clamped ones suggested by balala, if by any chance you'd like to be able to scroll indefinitely through your images (i.e. when you try to go past 9 you'll return to 0 and viceversa). If you want to stop at the boundaries, then use the clamped version of the formulas.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
balala
Rainmeter Sage
Posts: 16168
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Formula in MeasureName

Post by balala »

Yincognito wrote: March 19th, 2023, 10:24 pm This, of course, assumes that your MeasureImageNDownload (where N ranges from 0 to 9) measures produce strings that represent valid paths to your images, and that you initialized the ScrollPos variable to some value beforehand in your skin.
Obviously I also assumed this, even if I didn't mentioned it expressly.
Yincognito wrote: March 19th, 2023, 10:24 pm If you wonder, the formulas in the mouse actions are an alternative to the clamped ones suggested by balala,
As usually: one question, more possible solutions...
User avatar
Yincognito
Rainmeter Sage
Posts: 7157
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Formula in MeasureName

Post by Yincognito »

balala wrote: March 20th, 2023, 3:18 pm Obviously I also assumed this, even if I didn't mentioned it expressly.

As usually: one question, more possible solutions...
Indeed. I only mentioned this to prevent misunderstanding since I didn't post a full code. And yeah, you know me, I'm a fan of never ending scrolling haha, so I thought such an alternative would be good to know, if by any chance needed by the OP or others that might read it in the future. Any variant is fine, depends on what the skin designer decides he eventually wants. :thumbup:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth