It is currently April 18th, 2024, 2:00 am

Help? Conditional operations

Get help with creating, editing & fixing problems with skins
User avatar
threethirtyseven111
Posts: 4
Joined: August 13th, 2014, 7:31 pm

Help? Conditional operations

Post by threethirtyseven111 »

I'm attempting to make an edit of eclectic_tech's sticky notes skin - more specifically, adding tabs. The problem is, when I'm trying to use conditional operations, Rainmeter doesn't seem to like it and the tab meters don't show up at all. Here's the code:

Code: Select all

[variables]
note=1
size=8
*a couple more irrelevant variables*

[chara]
background stuff...

[sticky]
more background stuff...neither use #notes#

*/[tab] and [stuff] are just to see if #notes# is responding
[tab]
measure=calc
formula=#notes#
DynamicVariables=1

[stuff]
meter=string
measurename=[tab]

[tab1]
Meter=Image
ImageName=(#note# = 1 ? tab_on.png : tab_off.png)
DynamicVariables=1
x=200
y=120
LeftMouseUpAction = !SetVariable note (1)

[tab2]
*and so on
I've tried both ImageName=tab_on.png and tab_off.png, which work, so the problem isn't the images. I've also tried putting the names in quotation marks, but that doesn't work either. And the code I put in to make sure #note# is working ([tab] and [stuff]) doesn't work either. But there's nothing I can see that's getting in the way.
...And if anyone has any suggestions of doing tabs in a better way, feel free to bring it up.
User avatar
VasTex
Posts: 407
Joined: September 20th, 2012, 3:17 pm
Location: USA - Montana

Re: Help? Conditional operations

Post by VasTex »

Here's a quote from the Manual regarding formulas and Conditional Operations:
Note: While Measures, Section Variables, Variables and Built-in Variables can be used in a formula they must not evaluate to a string that is not valid for use in a formula. For example 1+two is not valid.
That being said, the conditional you're trying to use will never work. They only evaluate to true/false using, or working with, numbers or variables whose values are numbers or equations. So, to get your current code to work with what you've given you'll need to change the image meter and add a measure.

Below is an edited version of the code you posted. I removed most of the gibberish and left the relevant information:
;This is what you had. *Notice Errors in Red & Comments in Green.
[variables]
note=1

[tab1]
Meter=Image
ImageName=(#note# = 1 ? tab_on.png : tab_off.png)
DynamicVariables=1
x=200
y=120
LeftMouseUpAction = !SetVariable note (1)
;I'm not sure if it was a copy/paste simplification on your part or
;if this is how the code was originally, but you should try and follow the proper format
;for these bangs given in the corrections below. Setting the variable 'Note'
;to (1) would literally set it to (1), not 1 as I assume you intended.
;This is what you need. *Notice Corrections in Blue & Comments in Green.
[variables]
Note=1

[mNote]
Measure=Calc
Formula=(#Note# = 1 ? -1 : -2)
Substitute="-1":"Tab_On.png","-2":"Tab_Off.png"

;This Formula takes the value of #Note# and evaluates it to -1 if
;it equals 1 and -2 if it equals something other than 1.
;Now that it has a numeric result it can substitute those values for
;strings (text). These new strings are then used as the value
;for the Image Meter below.



[Tab1]
Meter=Image
ImageName=[mNote]
X=200
Y=120
LeftMouseUpAction=[!SetVariable "Note" "1"]
;Enclosing bangs in [Brackets] allows you to fire multiple bangs at once if needed. This
;option is not required for single bangs, but it doesn't hurt to include it. Second, the parameters
;of a bang should always be enclosed in quotations if you can help it.
;This helps to tell Rainmeter where one parameter starts and the other begins.
;It is especially important when dealing with file/folder paths as they may contain
;spaces which always need to be enclosed in quotations in order to be used in a bang.

DynamicVariables=1
This should solve your issue, but if it doesn't please let me know.
01010100 01100101 01100011 01101000 01101110 01101111 01101100 01101111 01100111 01101001
01100011 01100001 01101100 00100000 01000010 01100001 01100100 01100001 01110011 01110011
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5391
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Help? Conditional operations

Post by eclectic-tech »

@threethirtyseven111

Hopefully Vastex's suggestions helped you get this working...
I would be interested in seeing what it looks like with your changes 8-)

I created that skin by modifying Manci5's original single note skin. :sly:
User avatar
threethirtyseven111
Posts: 4
Joined: August 13th, 2014, 7:31 pm

Re: Help? Conditional operations

Post by threethirtyseven111 »

Thanks VasTex, the code worked beautifully :thumbup:
So, just as clarification,
a) Can such conditional code not be used for strings of any sort? The reason I used it was because it worked in another skin - with numbers, though.
b) I'm still a little unclear about !SetVariable. As the usual googling amateur, I took the parenthesis from the examples here: http://rainmeter.net/forum/viewtopic.php?f=15&t=8792. On Rainmeter's official guide for !SetVariable, they do use the quotation marks, but I thought that was for strings?
User avatar
VasTex
Posts: 407
Joined: September 20th, 2012, 3:17 pm
Location: USA - Montana

Re: Help? Conditional operations

Post by VasTex »

Can such conditional code not be used for strings of any sort?
No, not really. By definition the conditionals take the values they are given and decide whether or not they are 'true' or 'false'. This works great for mathematical equations, for example A+B=C if A is 2 and B is 3 then the conditional would be 'true' if C was 5, but it would be 'false' is C was anything other than 5.

This system simply does not work with strings. Taking the previous example we can modify it to use plain strings like this: The+Cat=Dog. This could never evaluate to true or false in Rainmeter. Words cannot be equal to, or be subtracted from, other words using the IfConditions. That is what the IfMatch system is for.

In summary, IfCondition is for Numbers, Equations and Variables with numeric values. Whereas IfMatch is for Strings and Variables with string values.
I'm still a little unclear about !SetVariable...they do use the quotation marks, but I thought that was for strings?
!SetVariable has the same usage and proper formatting as almost all other bangs in Rainmeter. The correct usage of !SetVariable is:
[color=#0000FF][b][!SetVariable "VariableName" "NewValue" "ConfigContainingVariable"][/b][/color]
Please note that both the [brackets] and the Config parameters are optional. However, notice how every parameter is enclosed in quotations aside from the bang itself? This is to tell Rainmeter where one parameter ends and another begins. This is only needed on parameter values containing spaces, but it's good practice to include it on every parameter anyway.

For example when dealing with Strings:
[b][!SetVariable "PageTitle" [color=#0000FF]"This is a title"[/color]][/b]
*Thanks to the quotations Rainmeter understands that 'This is a title' is one, single parameter.

[b][!SetVariable "PageTitle" [color=#BF0000]This is a title[/color]][/b]
*Without the quotations Rainmeter takes each word as a new parameter. Thus the 'PageTitle' variable will be set to the value of 'This' and the optional 'Config' parameter will be set to the value of 'is' while the remaining words 'a' and 'title' will be ignored.


For example when dealing with Numbers:
[b][!SetVariable "PageNumber" "[color=#0000FF]4[/color]"][/b]
*With quotations the value of 'PageNumber' is set to whatever is inside of them, in this case it's 4.

[b][!SetVariable "PageNumber" "[color=#0000FF](#CurrentPage# + 1)[/color]"][/b]
*With quotations the value of 'PageNumber' is set to whatever is inside of them, in this case it's the equation (#CurrentPage# + 1). Rainmeter needs the quotations because our equation has spaces in it. The variable itself, however, needs (parenthesis) around it so that Rainmeter understands that it's all one entire equation. Without the parenthesis it's likely that Rainmeter would interpret #CurrentPage# + 1 as just #CurrentPage# and ignore everything following the first space since there is nothing telling it to group everything as one.

To sum it up, quotations are needed anytime any !Bang uses parameters containing spaces. Whether those parameters are numeric-based or string-based does not matter. If it has spaces, it needs quotations.

Parenthesis on the other hand are only needed when a !Bang contains a parameter containing a mathematical equation which, in turn, contains spaces. The equation 7-4 does not need parenthesis as it has no spaces, but the equation (7 - 4) does need parenthesis because it does have spaces.

Hopefully this cleared things up, but I do tend to be a little long-winded in my explanations so feel free to ask if anything didn't make sense.
01010100 01100101 01100011 01101000 01101110 01101111 01101100 01101111 01100111 01101001
01100011 01100001 01101100 00100000 01000010 01100001 01100100 01100001 01110011 01110011
User avatar
threethirtyseven111
Posts: 4
Joined: August 13th, 2014, 7:31 pm

Re: Help? Conditional operations

Post by threethirtyseven111 »

@VasTex

Thanks for the explanations again! And the length is fine, especially compared to the texts my English teacher insists on using :(

But I'm running into other problems on the exact same things...later in the skin, I tried this:

Code: Select all

[min]
Meter=Image
ImageName=moti.png
W=80
H=62
X=0
Y=0
DynamicVariables=1
Hidden=(#minimized# = 1 ? 0 : 1)
LeftMouseUpAction=[!SetVariable minimized 0][!Redraw]
It seemed like I was using the conditional correctly. But it didn't hide/show like it was supposed to until I did this:

Code: Select all

[minimizeds]
Measure=Calc
Formula=(#minimized# = 1 ? 0 : 1)

[min]
Meter=Image
ImageName=moti.png
W=80
H=62
X=0
Y=0
DynamicVariables=1
Hidden=[minimizeds]
LeftMouseUpAction=[!SetVariable "minimized" "0"][!Redraw]
Any insights? I'm grateful that it actually worked at all, but would like to know what in the world is going on to save myself some headache next time I do something like this.

And !SetVariable seems to be killing me again...It looks like the exact syntax but it's not working no matter what I try :confused: ...
User avatar
VasTex
Posts: 407
Joined: September 20th, 2012, 3:17 pm
Location: USA - Montana

Re: Help? Conditional operations

Post by VasTex »

Well, I see no reason why your first example wouldn't work. I tested it myself and it worked just fine. I've posted my example (edited from your first) below. I made a few changes that I'll note in the comments of the code. As for your second example, like you mentioned, it works just fine as well. Both examples work actually.

Example 1:
[Rainmeter]
Update=1000

[Variables]
Minimized=0
;I swapped the value to work with the edited logic below

[min]
Meter=Image
W=120
H=120
SolidColor=0,0,0,255
DynamicVariables=1
Hidden=(#Minimized# = 0 ? 0 : 1)
;I swapped the values around to make the 'Default' value 0 or visible
;This made more sense to me with only the code you gave, but perhaps
;it makes sense the way you had it with the rest of your code.

LeftMouseUpAction=[!SetVariable "Minimized" "1"][!UpdateMeter "min"][!Redraw]
;I added the additional bang [!UpdateMeter "min"] to the action
;This bang, along with the others, Sets the variable, updates the meter
;to grab the newest values and then redraws it show those new values.
As for the second example you posted... please change Minimizeds to Minimized the 's' hurts me...

Anyway to be quite honest none of these conditionals are even necessary. I feel like you may be over complicating things. You can do what you need to do using the edited example below.

Fixed Example 1:
[Rainmeter]
Update=1000

[Variables]
Minimized=0

[min]
Meter=Image
W=120
H=120
SolidColor=0,0,0,255
DynamicVariables=1
Hidden=#Minimized#
;There's no need for a conditional here. The SetVariable will take care of it.
LeftMouseUpAction=[!SetVariable "Minimized" "1"][!UpdateMeter "min"][!Redraw]
And !SetVariable seems to be killing me again...It looks like the exact syntax but it's not working no matter what I try...
Your use of the bang seems just fine. I feel like you're attributing the issues you had to the bang itself when they're really not the issue. As in your second example it is typically in everyone's best interest to keep parameters enclosed in quotations as you have them.
01010100 01100101 01100011 01101000 01101110 01101111 01101100 01101111 01100111 01101001
01100011 01100001 01101100 00100000 01000010 01100001 01100100 01100001 01110011 01110011
User avatar
threethirtyseven111
Posts: 4
Joined: August 13th, 2014, 7:31 pm

Re: Help? Conditional operations

Post by threethirtyseven111 »

@VasTex

Thank you again for your useful suggestions! And for pointing out that I didn't need a conditional (I think it was left over from when I was using a cyclic variable at first...)
And. Uh. The "s" stands for section...helps me differentiate between the calc measure and the variable #minimized#...probably unnecessary, but I get easily confused :)

I looked at some more !SetVariable tutorials, which didn't really tell me more. It seems like I might have to try redownloading to see if that works...
User avatar
VasTex
Posts: 407
Joined: September 20th, 2012, 3:17 pm
Location: USA - Montana

Re: Help? Conditional operations

Post by VasTex »

Personally I use the usual programming standard of labeling things to prefix my sections as opposed to adding a postfix.

So instead of Minimizeds I would use sMinimized (lowercase 's' followed by a capital). I tend to use 'm' for measure, 's' for style 'g' for group and nothing for a meter, but that's just me. Also, I don't think re-downloading anything is going to fix a single bang. Is there something more specific that isn't working with them? If the code you posted earlier still isn't working just post the entirety of your code. It's much easier to test when we have everything and not just little snippets.
01010100 01100101 01100011 01101000 01101110 01101111 01101100 01101111 01100111 01101001
01100011 01100001 01101100 00100000 01000010 01100001 01100100 01100001 01110011 01110011