It is currently February 4th, 2023, 3:02 am

Problem with setting dynamic function of a button

Get help with creating, editing & fixing problems with skins
Hylia
Posts: 7
Joined: September 20th, 2022, 12:57 am

Problem with setting dynamic function of a button

Post by Hylia »

So I am attempting to make a simple button that, basically, turns my skin's "edit mode" on if its off, and off if its on. I found this thread from several years ago on this very topic and it has been very enlightening for getting me this far, but I have hit a bit of a snag. To my eyes I have followed the instructions to the letter, but the button is still not working and I don't know why at this point. I am hoping that someone here will be able to look at my script and see where I went wrong.

Code: Select all

[MeasureEditMode]
Measure=Calc
Formula=#EditMode#
IfCondition=(#CURRENTSECTION#=1)
IfTrueAction=[!SetOption MeterEditModeButton LeftMouseUpAction "[!SetVariable Variables EditMode 0 "Settings.inc"]"][!SetOption MeterEditModeButtonText Text "Turn Edit Mode OFF"][!UpdateMeter "MeterEditModeButton"][!UpdateMeter "MeterEditModeButtonText"][!Redraw]
IfFalseAction=[!SetOption "MeterEditModeButton" LeftMouseUpAction "[!SetVariable Variables EditMode 1  "Settings.inc"]"][!SetOption MeterEditModeButtonText Text "Turn Edit Mode ON"][!UpdateMeter "MeterEditModeButton"][!UpdateMeter "MeterEditModeButtonText"][!Redraw]
DynamicVariables=1
Here is what I have for my measure. I'm storing the variable being changed within a separate .inc file for various settings, but that aside as far as I can tell, the measure is identical to the example balala gave. Funnily enough, the text on the button does actually change dependent on the state of the variable, but otherwise the measure doesn't seem to be doing anything. And yes the variables section does have DynamicVariables set to 1.

Code: Select all

[MeterEditModeButton]
Meter=Shape
Shape=Rectangle 0,0, 80,50 | Fill Color 0,0,0,1 | StrokeWidth 3 | StrokeColor #BaseColor#
X=5
Y=230
LeftMouseUpAction=[!SetVariable EditMode "(1-#EditMode#)" "Settings.inc"][!UpdateMeasure "MeasureEditMode"][!UpdateMeter "#CURRENTSECTION#"]
DynamicVariables=1


[MeterEditModeButtonText]
Meter=String
MeterStyle=StyleString
StringAlign             = centercenter
FontSize=6
    clipString              = 2
    H                       =30
    W                       =50
	X=40r
	Y=25r


Text=
DynamicVariables=1
And here is what I have for the button, nothing too noteworthy going on here. I'm not entirely sure what "(1-#EditMode#)" is doing since the variable being changed has already been defined as #EditMode#, but thats how it was in balala's example. I was able to make it kinda work by defining LeftMouseUpAction as

Code: Select all

LeftMouseUpAction=[!WriteKeyVariable EditMode 1 "Settings.inc"][!UpdateMeasure "MeasureEditMode"][!UpdateMeter "#CURRENTSECTION#"]
but that only get me as far as editing the variable in that direction, and since I want to be able to toggle it both ways with the same button, thats not that helpful. I hope y'all are able to see whats probably a really simple step I missed somewhere in here, because I can't find the mistake. Thank you.
User avatar
balala
Rainmeter Sage
Posts: 14935
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Problem with setting dynamic function of a button

Post by balala »

Hylia wrote: January 18th, 2023, 6:27 pm So I am attempting to make a simple button that, basically, turns my skin's "edit mode" on if its off, and off if its on.
  • When you have quotes into an expression which you want to set with any kind of bang (!SetOption in this case, but the same applies to the !SetVariable - and not just - bang as well), including the expression into simple double-quotes (") is not working properly, because Rainmeter stes only what you have between the first pair of quotes. For instance the first bang of the IfTrueAction option above is this: [!SetOption MeterEditModeButton LeftMouseUpAction "[!SetVariable Variables EditMode 0 "Settings.inc"]"]. The appropriate pairs of quotes are the ones set to the same color. But Rainmeter sets for the LeftMouseUpAction option of the [MeterEditModeButton] meter, only what is contained between the first red and the first green quotes, because it takes into account the first two quotes. And this leads immediately to an error, because in this expression the first bracket (the one following the first quote - this is colored light blue above) has no closing pair. In such cases the first pair of quotes has to be Magic Quotes (which means you have to triple them): [!SetOption MeterEditModeButton LeftMouseUpAction """[!SetVariable Variables EditMode 0 "Settings.inc"]"""]. This way you let Rainmeter to know exactly the pairs. But in fact this is not exactly the case in this case (see below).
  • The above way set !SetVariable bangs (set to the LeftMouseUpAction option of the [EditModeButton] meter) are wrong themselves as well, because they have too much parameters. !SetVariable may have two or three parameters, namely:
    • The name of the variable you want to set (this should be EditMode I assume).
    • The value you want to set for the previously mentioned variable (0 probably in this case).
    • If added a third parameter as well, this has to be the name of the config in which you want to set the variable. If this parameter is not given, the variable is set into the current skin, but if it's there, the variable will be set into the activated skin of that config. Note that you here used a skin name, not a name of a config. There is a great difference between these two. Rainmeter identifies the skin based on its config name, not based on the name of the .ini file.
    • The name of the Variables section, added in this case as the second parameter, is not needed.
    As far as I can tell, the bangs should look like this:

    Code: Select all

    [MeasureEditMode]
    ...
    IfTrueAction=[!SetOption MeterEditModeButton LeftMouseUpAction "[!SetVariable Variables EditMode 0]"][!SetOption MeterEditModeButtonText ...
    IfFalseAction=[!SetOption "MeterEditModeButton" LeftMouseUpAction "[!SetVariable Variables EditMode 1]"][!SetOption MeterEditModeButtonText ...
    ...
    Note that since I removed the skin name (Settings.ini, which has been the fourth parameter) from the !SetVariable bangs, I didn't add the Magic Quotes, but kept the not-paired quotes. also note that I pasted here only the first !SetOption bang of both options.
  • Besides all this, I still believe there is no need to set the LeftMouseUpAction options in such a complicated way. This LeftMouseUpAction option should be something like this:

    Code: Select all

    [MeterEditModeButton]
    ...
    LeftMouseUpAction=[!SetVariable EditMode "(1-#EditMode#)"][!UpdateMeasure "MeasureEditMode"][!UpdateMeter "#CURRENTSECTION#"]
    ...
    (note the removed Settings.ini skin name from the !SetVariable bang)
  • If you do this, the [MeasureEditMode] measure simplifies a little bit as well:

    Code: Select all

    [MeasureEditMode]
    Measure=Calc
    Formula=#EditMode#
    IfCondition=(#CURRENTSECTION#=1)
    IfTrueAction=[!SetOption MeterEditModeButtonText Text "Turn Edit Mode OFF"][!UpdateMeter "MeterEditModeButtonText"][!Redraw]
    IfFalseAction=[!SetOption MeterEditModeButtonText Text "Turn Edit Mode ON"][!UpdateMeter "MeterEditModeButtonText"][!Redraw]
    DynamicVariables=1
  • Hylia wrote: January 18th, 2023, 6:27 pm And yes the variables section does have DynamicVariables set to 1.
    The [Variables] can't have set dynamic variables. Dynamic variables doesn't work on this section and on [Metadata] either.
  • Hylia wrote: January 18th, 2023, 6:27 pm I'm not entirely sure what "(1-#EditMode#)" is doing since the variable being changed has already been defined as #EditMode#, but thats how it was in balala's example.
    The [!SetVariable EditMode "(1-#EditMode#)"] bang switches the value of the EditMode variable between 0 and 1. When the variable is 0 if the bang is executed, EditMode becomes 1 and vice-versa, from 1 it becomes 0. For each of these values the IfTrueAction and IfFalseAction options of the [MeasureEditMode] measure are executing the appropriate bangs.
  • In order to get this working, make sure you have defined an initial value for the EditMode variable into the [Variables] section. For instance:

    Code: Select all

    [Variables]
    ...
    EditMode=1
  • If you don't have this, the [!SetVariable EditMode "(1-#EditMode#)"] bang doesn't work either, because (1-#EditMode#) has no numerical value. So check if you did define the variable.
  • Hylia wrote: January 18th, 2023, 6:27 pm

    Code: Select all

    LeftMouseUpAction=[!WriteKeyVariable EditMode 1 "Settings.inc"][!UpdateMeasure "MeasureEditMode"][!UpdateMeter "#CURRENTSECTION#"]
    A !WriteKeyVariable bang doesn't exist. There is a !WriteKeyValue, but not !WriteKeyVariable.
Hope you do get your code working. since you've posted only some snippets, I can't help you more. If you can't get your code working properly, for first please post the whole code.
Hylia
Posts: 7
Joined: September 20th, 2022, 12:57 am

Re: Problem with setting dynamic function of a button

Post by Hylia »

Thank you, that is very helpful! Using your advice I was able to get my code working with one small caveat. You see, it was important to me to have the variable stored in settings.inc because its main function is to be referenced by another config. Now I know I could just keep it in this config and have the other one reference this one, but I find it annoying to deal with during testing and I think this is an overall cleaner way to deal with the problem. Anyway, when I tried to edit the bangs to point towards the variable in settings.inc, it again ceased to function. Could it be that "(1-#EditMode#)" doesn't work with the WriteKeyValue bang? And if that is the case, what do you think would be the best way to go about it? Again I feel like I'm missing something obvious, like trying to use a bang that doesn't exist :handtohead:

I didn't post my whole code initially because there is a lot going on that is sorta half finished and not relevant to the specific problem I am having, but here is my github repo since you asked. The code I am having trouble with is in settings\colorpickerplus.ini.

EDIT: Nevermind I found my mistake. I spent all day trying various bang and syntax combinations...only to realize that it was missing the [!refresh] bang. -_- I'm gonna go hide in the corner now...
Thanks again for the advice balala, you've been a massive help
User avatar
balala
Rainmeter Sage
Posts: 14935
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Problem with setting dynamic function of a button

Post by balala »

Hylia wrote: January 20th, 2023, 8:12 pm EDIT: Nevermind I found my mistake. I spent all day trying various bang and syntax combinations...only to realize that it was missing the [!refresh] bang.
I'm glad if you got it working well, especially that you figured out the solution by yourself. Good job.
Hylia wrote: January 20th, 2023, 8:12 pm I'm gonna go hide in the corner now...
Don't worry, you're not the only one who faced this problem, so don't go. You don't have to...