It is currently April 19th, 2024, 4:34 am

Change image with variables

Get help with creating, editing & fixing problems with skins
janoot
Posts: 31
Joined: December 22nd, 2014, 2:14 pm

Change image with variables

Post by janoot »

Hello, I'm trying to change my Image with variables, but I don't think I get how the variables work yet.

Right know I use this:

Code: Select all

[Rainmeter]
Update=1000

[Variables]
Imgname=#@#img.png

[MeterImg]
Meter=Image
ImageName=Imgname
w=50
h=50
Leftmouseupaction=!SetVariable "Imgname" #@#blur.png
Leftmouseupaction=!SetWallpaper Imgname
It seems to going wrong already by using "ImageName=Imgname", since the image is not being displayed. The wallpaper doesn't change as well.
janoot
Posts: 31
Joined: December 22nd, 2014, 2:14 pm

Re: Change image with variables

Post by janoot »

Thank you for the quick reply, but I'm more interested in making my own skin, so it fits with the style of the other skins I've made.

I need to know how I can let the ImageName respond to a change in variables.
User avatar
winterwulf
Posts: 94
Joined: August 17th, 2016, 1:48 am
Location: São Paulo - Brazil

Re: Change image with variables

Post by winterwulf »

janoot wrote:Thank you for the quick reply, but I'm more interested in making my own skin, so it fits with the style of the other skins I've made.

I need to know how I can let the ImageName respond to a change in variables.
Try Dynamic variables
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Change image with variables

Post by balala »

janoot wrote:Hello, I'm trying to change my Image with variables, but I don't think I get how the variables work yet.

It seems to going wrong already by using "ImageName=Imgname", since the image is not being displayed. The wallpaper doesn't change as well.
There are only two places where we're using the names of the variables, without including them between two # characters: when we initialize them, within the [Variables] section (as you did) and into the !SetVariable bangs (as you also did into the LeftMouseUpAction). Otherwise every time we want to use the value, we have to include its name between # characters.
So, first replace the ImageName option of the [MeterImg] meter, with the following one: ImageName=[color=#FF0000]#[/color]Imgname[color=#FF0000]#[/color]. Add the same characters around the Imgname variable name, into the !SetWallpaper bang: [!SetWallpaper #Imgname#] (see furtherly another problem, too).
Second: you can't use two LeftMouseUpAction options on the same [MeterImg] meter. Only one (the first) of any option is allowed onto one meter / measure / section. Replace for example the second LeftMouseUpAction, with RightMouseUpAction: use RightMouseUpAction=[!SetWallpaper Imgname], instead of Leftmouseupaction=!SetWallpaper Imgname.
Third: the value which you're setting to the variable, with the LeftMouseUpAction option, probably contains spaces, even if these spaces are not visible (the #@#blur.png expression itself doesn't has any spaces, but if the #@# variable is replaced by its real value, it probably will contain one or more spaces). As such, it's also a very good idea, to include it into quotations: LeftMouseUpAction=[!SetVariable "Imgname" [color=#FF0000]"[/color]#@#blur.png[color=#FF0000]"[/color]]
And finally, as winterwulf said, you have to add a DynamicVariables=1 option to the meter or measure which is using the newly set variable (in this case to the [MeterImg] meter).
janoot
Posts: 31
Joined: December 22nd, 2014, 2:14 pm

Re: Change image with variables

Post by janoot »

I hadn't heard of the dynamic variables thing, but now it works. Thanks everyone!
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Change image with variables

Post by balala »

janoot wrote:I hadn't heard of the dynamic variables thing, but now it works.
When you set a new value to a variable, using the !SetVariable bang, you have to add a DynamicVariables=1 option to the meter or measure where you want to use the variable. Without this option, the meter or measure can't use the new value. Because eg the [Rainmeter] section doesn't accept dynamic variables, you can't use there a dynamically set variable.