It is currently April 20th, 2024, 1:45 pm

Use #variable# in a @include= Line?

Get help with creating, editing & fixing problems with skins
User avatar
CodeCode
Posts: 1365
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Use #variable# in a @include= Line?

Post by CodeCode »

Hello, so I have an idea for an end user to have easy access to several color schemes preset in my skin.

What I am trying, but failing in, is using a variable in the @include=#@#variables#num#.inc

It has not been working. So, am I trying something hat is semantically or inherently 'not allowed'? Or is there another step needed to get the variable to work.

I am using a context menu to switch the #num# variable for any one of a possible 5 different color schemes.

SOmething like this:

Code: Select all

[Rainmeter]
ContextTitle=Variables.inc
ContextAction="#@#Variables.inc"
ContextTitle2=Crimson
ContextAction2=[!WriteKeyValue Variables num "1" "#@#Variables#num#.inc"][!RefreshGroup Neo]
...
...
I am fairly certain using the #num# variable in the WriteKeyValue scope for the config, is not logically sound, but that is in essence what I sort of came up with, but no visible result, other than the @include becomes 'invisible' and everything goes to white and the inc then is broken.

What to do?

Thanks
CC
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
CodeCode
Posts: 1365
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Use #variable# in a @include= Line?

Post by CodeCode »

https://docs.rainmeter.net/tips/include-guide/
We can also use a variable to define an @include. The only caveat is that variable cannot be dynamic.
Ok, I see the problem. I will just have to list out the includes and somehow trigger between them somehow.

So now I am not only confused, but stuck entirely.
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

Re: Use #variable# in a @include= Line?

Post by death.crafter »

CodeCode wrote: June 16th, 2021, 3:15 am Hello, so I have an idea for an end user to have easy access to several color schemes preset in my skin.

What I am trying, but failing in, is using a variable in the @include=#@#variables#num#.inc
https://docs.rainmeter.net/manual-beta/variables/nesting-variables/
from the Realm of Death
User avatar
CodeCode
Posts: 1365
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Use #variable# in a @include= Line?

Post by CodeCode »

Ok,
so I have tried several different nested variable variants, to no avail. I do not think I am using these correctly.

I also read that an @include can be anywhere in the ini or inc. Also that the [Variables] section cannot have a dynamic arriable in it. So I movedmy include to the bottom, checked it was working then tried several nested variables.

Sort of to these:

@include=#@#variables#1#.inc

@include=#@#variables[#1].inc

@include=[#@#variables[#1]].inc

But the plot thickens in this next part.
As I explained in my OP that I was trying to use a context menu to switch between variables.iinc'c the issue is that every varisbles#num#.inc file will not be identical, and that is the problem, where am I using WriteKeyValue? or just SetVariable in the context menu.

The last hurdle, is once I put any kind of nested variable in the way I am trying, the context menu becomes invisible, as in not there for the user to see.

I m lost on these variables, mostly because the context menu also is using the same variable #num#. I dont think I have to do it only in the context menu, so I am working on other approaches, but nothing is panning out atm. :oops:
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

Re: Use #variable# in a @include= Line?

Post by death.crafter »

CodeCode wrote: June 16th, 2021, 3:15 am SOmething like this:

Code: Select all

[Rainmeter]
ContextTitle=Variables.inc
ContextAction="#@#Variables.inc"
ContextTitle2=Crimson
ContextAction2=[!WriteKeyValue Variables num "1" "#@#Variables#num#.inc"][!RefreshGroup Neo]
...
...
Umm I didn't check your first post thoroughly since you said you figured it out in the second. So what you are doing here is absolutely nuts.

What is wrong?
  • You are writing the variable to a file which uses the variable. Like let your current num is 2. Then you are writing a variable num=1 to Variables2.ini. Then refreshing the group.
  • And the above point would work, even if it will be wrong, if and only if the variable num is declared in the main ini or in an inc other than the Variables{num}.inc ones, which I am pretty positive is not the case

How to make it work:
  • Declare a variable num in an include file that is static(since you are using a number of skins you need to include one static variable file in all the skins).
  • Then use just [!WriteKeyValue Variables num "1" "static\variable\file\path"][!other bangs]

Additional notes:
  • Though includes work everywhere, make a habit of suffixing the intent of including it. Because you can't use more than one @include as one section can't have more than one keys of the same name.
    Like for theme include @includeTheme=#@#Theme#ThemeNum#.inc
    You can make it @include1 @include2 etc, but this way you don't have to look twice what is it.
  • And @include=#@#Variables#num#.inc will work just fine as long as there is a variable called num declared in the skin.
  • Tip: When making themes or color schemes it's better to use the name of the theme or color scheme as file name rather than numberizing it. Then you can use a variable as Theme or ColorScheme and set it to the corresponding names to change things.
    E.g.

    [Variables]
    Theme=Dark


    and theme file would be Dark.inc and you can include using

    @includeTheme=#@##Theme#.inc

ProTip:

Use log while making a skin. It will show you exactly where you went wrong.
from the Realm of Death
User avatar
Active Colors
Moderator
Posts: 1251
Joined: February 16th, 2012, 3:32 am
Location: Berlin, Germany

Re: Use #variable# in a @include= Line?

Post by Active Colors »

CodeCode wrote: June 16th, 2021, 3:15 am Hello, so I have an idea for an end user to have easy access to several color schemes preset in my skin.

What I am trying, but failing in, is using a variable in the @include=#@#variables#num#.inc

It has not been working. So, am I trying something hat is semantically or inherently 'not allowed'? Or is there another step needed to get the variable to work.

I am using a context menu to switch the #num# variable for any one of a possible 5 different color schemes.

SOmething like this:

Code: Select all

[Rainmeter]
ContextTitle=Variables.inc
ContextAction="#@#Variables.inc"
ContextTitle2=Crimson
ContextAction2=[!WriteKeyValue Variables num "1" "#@#Variables#num#.inc"][!RefreshGroup Neo]
...
...
I am fairly certain using the #num# variable in the WriteKeyValue scope for the config, is not logically sound, but that is in essence what I sort of came up with, but no visible result, other than the @include becomes 'invisible' and everything goes to white and the inc then is broken.

What to do?

Thanks
CC
1. Same as what death.crafter said, judging by your short code snippet you do not have a declared #num# variable. By looking at your code snippet it seems to me that you want to call external inc file with @include=#@#variables#num#.inc but the #num# variable is announced in that external inc. This obviously won't work. You need to announce the #num# somehow.

If the includes are messed up you would see this error:
Capture.PNG
If we are wrong then I can't seem to follow your struggle with @includes. You need to show us a bit more than what I see in your post above. I would check the Variables sections in this skin and in the relevant include files.

2. What does the log say? Any errors?

3. Make sure all your files (main skin ini and external incs) are encoded with "UTF-16 LE" encoding (also know as"UCS-2 LE BOM" encoding).

4. I've made a simplified code in case you are struggling with @includes.
skin.ini

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
ContextTitle=Color 1
ContextAction=[!WriteKeyValue Variables num "1"][!Refresh]
ContextTitle2=Color 2
ContextAction2=[!WriteKeyValue Variables num "2"][!Refresh]

[Variables]
num=1
@include1=#@#variables#num#.inc

[ObjBackground]
Meter=Image
X=0
Y=0
W=150
H=75
SolidColor=10,10,10
UpdateDivider=-1

[ObjText]
Meter=String
X=20
Y=20
FontFace=Arial
FontWeight=500
FontSize=12
FontColor=#color#
StringAlign=Left
ClipString=0
AntiAlias=1
Text=Scheme: #num# #CRLF#Color: #color#
DynamicVariables=1
UpdateDivider=-1
variables1.inc

Code: Select all

[Variables]
color=0,255,0
variables2.inc

Code: Select all

[Variables]
color=255,0,0
5. Additional note.
This will work:

Code: Select all

[Variables]
num=1
@include1=#@#variables#num#.inc
This will NOT work:

Code: Select all

[Variables]
@include1=#@#variables#num#.inc
num=1
You do not have the required permissions to view the files attached to this post.
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

Re: Use #variable# in a @include= Line?

Post by death.crafter »

Active Colors wrote: June 16th, 2021, 10:07 am 3. Make sure all your files (main skin ini and external incs) are encoded with "UCS-2 LE BOM" encoding.
Is there a particular reason for this? Cause UTF-8 or UTF-16(which I use) work pretty fine.
from the Realm of Death
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Use #variable# in a @include= Line?

Post by jsmorley »

death.crafter wrote: June 16th, 2021, 10:13 am Is there a particular reason for this? Cause UTF-8 or UTF-16(which I use) work pretty fine.
UCS-2 LE BOM is just the Notepad++ term for UTF-16 Little Endian. NEVER encode Rainmeter .ini or .inc files as UTF-8 with or without BOM. While they can work, they will only work if you don't use any characters above 127 in the ASCII character set. Always encode Rainmeter files as UTF-16 Little Endian.

https://docs.rainmeter.net/tips/unicode-in-rainmeter/
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

Re: Use #variable# in a @include= Line?

Post by death.crafter »

jsmorley wrote: June 16th, 2021, 10:22 am UCS-2 LE BOM is just the Notepad++ term for UTF-16 Little Endian. NEVER encode Rainmeter .ini or .inc files as UTF-8 with or without BOM. While they can work, they will only work if you don't use any characters above 127 in the ASCII character set. Always encode Rainmeter files as UTF-16 Little Endian.

https://docs.rainmeter.net/tips/unicode-in-rainmeter/
Ahh I see. I use UTF-16 since it displays pretty much all the characters. I will switch to LE version then. Thanks for letting me know.
from the Realm of Death
User avatar
Active Colors
Moderator
Posts: 1251
Joined: February 16th, 2012, 3:32 am
Location: Berlin, Germany

Re: Use #variable# in a @include= Line?

Post by Active Colors »

death.crafter wrote: June 16th, 2021, 10:13 am Is there a particular reason for this? Cause UTF-8 or UTF-16(which I use) work pretty fine.
Because
1. When you create a new skin in Rainmeter the skin is encoded with UCS-2 LE BOM by default out of the box.
2. jsmorley says so https://forum.rainmeter.net/viewtopic.php?p=166711#p166711.

(As jsmorley said above, UCS-2 LE BOM is a Notepad++ term. Because I always use Notepad++ I simply always forget that Unicode outside of Notepad++ is also called UTF-16 LE. My apologies for confusion. I edited this in my post. The manual describes all this btw https://docs.rainmeter.net/tips/unicode-in-rainmeter/)