It is currently May 2nd, 2024, 3:17 am

Having the Variables from a !WriteKeyValue Take effect

Get help with creating, editing & fixing problems with skins
Wyld_Goose
Posts: 36
Joined: May 12th, 2012, 3:23 am

Having the Variables from a !WriteKeyValue Take effect

Post by Wyld_Goose »

Is the usage of !Refresh or !Refresh #CURRENTCONFIG# when using a !WriteKeyValue purely for the changes to the Variable to take effect in the skin?


I ask this because I had already had !SetVariables in my skin that worked just fine and needed to be able to have settings saved when the skin was reset or turned off and then on again, so this brought me to !WriteKeyValue Variables.

So because I was learning as I went along I proceeded to set a !WriteKeyValue after all of my !SetVariable codes. This worked very well. Then as I proceeded to read the forums and Manual, I saw I had messed up and hadn't included a !Refresh to make it all work...

Well that's when it all stopped working! Actually it still worked just badly. very jumpy and slow to respond to the changes because the entire skin has to be refreshed for the change to happen rather then just the variable and the codes tied to it.

well nothing makes sense without examples so here goes. this is just a simple "Light Switch" On/Off code:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[Variables]
@Include=#@#Variables.inc
Settings=#@#Variables.inc




;-------------------Switches on and off------------------
[Switch]
Meter=Image
ImageName=#@#Images\switch#Num1#.png
LeftMouseUpAction=!Execute [!WriteKeyValue Variables Num1 (1-#Num1#) "#Settings#"][!WriteKeyValue Variables Core (1-#Core#) "#Settings#"][!Refresh #CURRENTCONFIG#]
DynamicVariables=1
X=0
Y=0
W=28
H=51
UpdateDivider=3600
Now mind you this is just a simple example and an entire skin reset doesn't really seem like an issue. But if this is in a very large skin and I just wanted this "switch" to "Turn on", take effect and the variables to be saved to the .inc file so all settings are saved when the skin is reset why wouldn't I do this:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[Variables]
@Include=#@#Variables.inc
Settings=#@#Variables.inc




;-------------------Switches on and off------------------
[Switch]
Meter=Image
ImageName=#@#Images\switch#Num1#.png
LeftMouseUpAction=!Execute [!SetVariable Num1 (1-#Num1#)][!WriteKeyValue Variables Num1 (1-#Num1#) "#Settings#"][!SetVariable Core (1-#Core#)][!WriteKeyValue Variables Core (1-#Core#) "#Settings#"][!UpdateMeter "Switch"]
DynamicVariables=1
X=0
Y=0
W=28
H=51
UpdateDivider=3600
When I code it that way, the Image.png switches back and forth from the two images (a light switch on (up) and off (down) because of the !UpdateMeter, is only being updated ever hour when not in use because of the UpdateDivider, The variables are changed in the .inc file for the purpose of saved settings, and the effects caused by the variable changes are very smooth because the entire skin isn't being reset.

Is there something here that I'm not understanding? Just because it seems to me that this is working doesn't mean I'm not seeing a possible problem down the road. Any input would be appreciated. Am I setting myself up for a problem later in my coding, or have I stumbled on a better way to have the Variable change to take effect in the skin?
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Having the Variables from a !WriteKeyValue Take effect

Post by Kaelri »

There's nothing wrong with doing it that way. Using !Refresh after !WriteKeyValue is helpful mainly when you need to apply the new value in a context where dynamic variables (i.e. !SetVariable) cannot be used - for example, when changing settings on a WebParser measure.

It's also a tiny bit better in terms of performance. Using !SetVariable requires dynamic variables for all affected meters/measures, and overusing dynamic variables in a skin, especially a big one, can really slow things down. Of course, refreshing the skin after every button press is not very smooth, either. So whether you should use one method or the other is entirely a matter of context. As a rule of thumb, I would use !WriteKeyValue + !SetVariable when UI responsiveness is at stake, or the variable is (or is likely to be) updated frequently.
Wyld_Goose
Posts: 36
Joined: May 12th, 2012, 3:23 am

Re: Having the Variables from a !WriteKeyValue Take effect

Post by Wyld_Goose »

Thanks, that's exactly what I was thinking, just wanted to be sure.