It is currently March 28th, 2024, 5:12 pm

Referencing to a variable using a variable in its name :/

Get help with creating, editing & fixing problems with skins
Post Reply
User avatar
Pflosch
Posts: 39
Joined: May 24th, 2020, 7:04 am
Location: Switzerland

Referencing to a variable using a variable in its name :/

Post by Pflosch »

Hi,

I have variables x1 - x20 and a variable y which takes values from 1 to 20.
Now, I'd like to set variable z to the value of x1-20 depending on status of y.

[!setVariable z x#y#] sets z to the name of the variable, but of course not to the value... :/

Is there any syntax to achieve this, or do I need to take the long way with some IfMatch... ?
User avatar
Halloyo
Posts: 31
Joined: June 17th, 2020, 3:08 am

Re: Referencing to a variable usng a variable in its name :/

Post by Halloyo »

I'm not sure I quite understand, but I think this could help? [!SetVariable z #x1##y1#]

All variables usually are surrounded by #, but they have a different syntax if they're nested. If this isn't it, then maybe look at nested variables: https://docs.rainmeter.net/manual/variables/nesting-variables/
User avatar
Pflosch
Posts: 39
Joined: May 24th, 2020, 7:04 am
Location: Switzerland

Re: Referencing to a variable using a variable in its name :/

Post by Pflosch »

Hi and thanks,

Yeah, I looked into these, but didn't get to something working. Also your suggestion can't work here.

I want to set z to the value of any x1-x20, whereas the number to be picked is the y variable.(There's no y1 or y2)
So the used syntax cannot include a specific x1 or x13...
User avatar
Halloyo
Posts: 31
Joined: June 17th, 2020, 3:08 am

Re: Referencing to a variable using a variable in its name :/

Post by Halloyo »

What's the use case?

Also, I'm kind of slow so if, for example, y=20 then x=20 and then z=2020??
User avatar
Pflosch
Posts: 39
Joined: May 24th, 2020, 7:04 am
Location: Switzerland

Re: Referencing to a variable using a variable in its name :/

Post by Pflosch »

Nope, example:
x1=5
x2=345
x3=65
x4=111
etc... these are user variables in an .inc file.

When y=3, I want to set z to the value of x3, when y=1 i want to set z to the value of x1.
User avatar
Halloyo
Posts: 31
Joined: June 17th, 2020, 3:08 am

Re: Referencing to a variable using a variable in its name :/

Post by Halloyo »

Then I'm pretty sure you're going to have to use IfConditions...

Code: Select all


[MeasureY]
Measure=Calc
Formula=#y#
IfCondition=MeasureY=1
IfTrueAction=[!SetVariable z x[MeasureY]]
or

Code: Select all

IfTrueAction=[!SetVariable z x#y#]
Should work in theory, but it's very late so I didn't test it. Also, if this has to be dynamic, I'd probably find a way to "merge" x and y if possible (though it might not be)
User avatar
Pflosch
Posts: 39
Joined: May 24th, 2020, 7:04 am
Location: Switzerland

Re: Referencing to a variable using a variable in its name :/

Post by Pflosch »

Yeah, I'm also afraid I'll have to go the long way...
Thanks anyway, have a nice eve.
User avatar
Active Colors
Moderator
Posts: 1251
Joined: February 16th, 2012, 3:32 am
Location: Berlin, Germany
Contact:

Re: Referencing to a variable using a variable in its name :/

Post by Active Colors »

Pflosch,
Like Halloyo said you would rather need here to use Nesting Variables.
If I got you right what you want to achive will look like this:
[!SetVariable z [#X[#Y]]]
Works for me:
GIF.gif
User avatar
Pflosch
Posts: 39
Joined: May 24th, 2020, 7:04 am
Location: Switzerland

Re: Referencing to a variable using a variable in its name :/

Post by Pflosch »

Wow, I tried every syntax of nesting I could figure, didn't come to that.
Was fiddling around an hour or so....

Thanks heaps, thatz x-actly it :) YMMD
User avatar
Active Colors
Moderator
Posts: 1251
Joined: February 16th, 2012, 3:32 am
Location: Berlin, Germany
Contact:

Re: Referencing to a variable using a variable in its name :/

Post by Active Colors »

Pflosch wrote: June 28th, 2020, 9:33 am Wow, I tried every syntax of nesting I could figure, didn't come to that.
Was fiddling around an hour or so....

Thanks heaps, thatz x-actly it :) YMMD
You are welcome! :)
Post Reply