It is currently April 16th, 2024, 5:47 am

[BUG or Mistake] Formula in String section variable?

Report bugs with the Rainmeter application and suggest features.
User avatar
Yincognito
Rainmeter Sage
Posts: 7118
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

[BUG or Mistake] Formula in String section variable?

Post by Yincognito »

Sample skin:

Code: Select all

[Variables]
LastSong="(Artist)   ●   (Title)"

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
BackgroundMode=2
SolidColor=47,47,47,255

---Measures---

[MS_Rainmeter_Song]
Measure=String
String="(Artist)   ●   00:00   ●   (Title)"
IfMatch="^#LastSong#$"
IfNotMatchAction=[!SetVariable LastSong "[MS_Rainmeter_Song]"]
IfMatchMode=1
DynamicVariables=1

---Meters---

[MT_Rainmeter_PlayerTopic]
Meter=STRING
X=0
Y=0
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
Text="#LastSong#"
DynamicVariables=1
Issue: watch the log, it's self explanatory.
Question: am I missing something obvious here that I should correct and this is the expected behavior in these circumstances, or it's a bug? :confused:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: [BUG or Mistake] Formula in String section variable?

Post by jsmorley »

Let us look into that. It certainly appears that the String option on the String measure is evaluating that as a formula, and it shouldn't.

I think in the short-term, you might want to use some other characters than ( and ) there.
User avatar
Yincognito
Rainmeter Sage
Posts: 7118
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: [BUG or Mistake] Formula in String section variable?

Post by Yincognito »

jsmorley wrote: June 16th, 2020, 3:56 pm Let us look into that. It certainly appears that the String option on the String measure is evaluating that as a formula, and it shouldn't.

I think in the short-term, you might want to use some other characters than ( and ) there.
Ok, thanks for taking a look at it. :thumbup:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Yincognito
Rainmeter Sage
Posts: 7118
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: [BUG or Mistake] Formula in String section variable?

Post by Yincognito »

jsmorley wrote: June 16th, 2020, 3:56 pmI think in the short-term, you might want to use some other characters than ( and ) there.
Yeah, it turns out that replacing the brackets in my manually built string is not going to be enough. As I'm working on a NowPlaying skin (as you probably realized), the behavior is triggered even by the brackets that might exist within the "title" of the song (missing brackets also trigger the behavior) - and mass renaming files is not a pretty solution... :D

Just wanted to let you know of it. Other than that, no pressure, take your time in checking this out. ;-)
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Brian
Developer
Posts: 2678
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: [BUG or Mistake] Formula in String section variable?

Post by Brian »

This is actually caused by the !SetVariable bang. It checks for formulas in order to truncate any non-significant digits and remove any trailing 0's.

You can test this by adding a space in your bang: IfNotMatchAction=[!SetVariable LastSong " [MS_Rainmeter_Song]"]

Honestly, I am not sure there is any way to "properly" fix this without any backwards-compatibility issues. Our formula checker always checks if the first character is a '(' and that signals our math parser to evaluate a formula. Obviously this isn't used everywhere, but it is for this bang.

-Brian
User avatar
Yincognito
Rainmeter Sage
Posts: 7118
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: [BUG or Mistake] Formula in String section variable?

Post by Yincognito »

Brian wrote: June 17th, 2020, 7:39 pm This is actually caused by the !SetVariable bang. It checks for formulas in order to truncate any non-significant digits and remove any trailing 0's.

You can test this by adding a space in your bang: IfNotMatchAction=[!SetVariable LastSong " [MS_Rainmeter_Song]"]

Honestly, I am not sure there is any way to "properly" fix this without any backwards-compatibility issues. Our formula checker always checks if the first character is a '(' and that signals our math parser to evaluate a formula. Obviously this isn't used everywhere, but it is for this bang.

-Brian
That's unfortunate. It's basically choosing between keeping something "buggy" (i.e. discarding perfectly valid strings) and breaking backwards compatibility. Both choices are bad, in my view. This reminds me of the supposedly similar problem with Microsoft skipping 9 from their versions as it would have produced "issues" in making the OS think it's ... Windows 98 (just because it also started with a 9).

Anyway, in my usage case, I managed to workaround the issue through a combination of not using brackets (adding a leading space, while working, needlessly complicated other things in my code) and (unrelated to this issue, but relevant to the accuracy of the IfMatch when there are brackets in the name of the song) the :EscapeRegExp section variable parameter. Hopefully I'll manage to avoid any inconveniences related to this issue in the future.

Thank you both for the interest in this and your useful suggestions. ;-)
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Yincognito
Rainmeter Sage
Posts: 7118
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: [BUG or Mistake] Formula in String section variable?

Post by Yincognito »

I discovered another annoyance like the one I mentioned earlier:

Code: Select all

[Variables]
Original=blabla[w

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
BackgroundMode=2
SolidColor=47,47,47,255

---Measures---

[MeasureOriginal]
Measure=String
String=#Original#
UpdateDivider=-1
; The below doesn't work
OnUpdateAction=[!SetOption MeterTest Text #Original#]
; The below does work
; OnUpdateAction=[!SetOption MeterTest Text [MeasureOriginal]]
; The below does work
; OnUpdateAction=[!SetOption MeterTest Text #*Original*#]
DynamicVariables=1

---Meters---

[MeterTest]
Meter=STRING
X=0
Y=0
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
Text=
DynamicVariables=1
The 3rd choice, while it works for in-skin operations, it doesn't work for intra-skin operations (like passing a value between skins), so it's useless for my usage case, where I pass such values between the parent skin and the custom tooltip one using !SetOption. Fortunately, the 2nd choice works for both in-skin and intra-skin operations, but this means I'll have to convert all my variables to String measures... all because of these little quirks in the Rainmeter parser. Damn... :x

Just as an idea, wouldn't some hypothetically new section variable parameter, like, say, :SkipEvaluation solve these issues by forcing Rainmeter to discard / ignore any brackets or anything that is used to reference / express another variable, measure or formula, so that the string stays as it is and doesn't break the expected process (with or without throuwing an error, as it could be seen in the latter case)? Or, maybe something like that for both section variables and normal variables, as they both seem to be affected. By the way, adding that hypothetically new parameter wouldn't (and shouldn't) negatively affect backwards compatibilty - and should, of course, work for both in-skin and intra-skin operations. Just saying... :confused:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: [BUG or Mistake] Formula in String section variable?

Post by jsmorley »

OnUpdateAction=[!SetOption MeterTest Text """#Original#"""]

https://docs.rainmeter.net/manual/skins/option-types/#MagicQuotes


1.jpg
You do not have the required permissions to view the files attached to this post.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: [BUG or Mistake] Formula in String section variable?

Post by jsmorley »

As brian stated a couple of days ago, most of the time any purely "text" option value does not evaluate [SectionVariables] or (formulas). This is the case with the Text option on a String meter and the String option on a String measure. However the !SetOption bang always DOES, as it is a general-purpose way to set a value on any option, both numbers and strings. So in my view, Magic Quotes are going to be a decent habit if you are using !SetOption to set a string value that is based on some [SectionVariable] or #Variable# where you don't have control over the contents, and can't be sure what will be passed.
User avatar
Yincognito
Rainmeter Sage
Posts: 7118
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: [BUG or Mistake] Formula in String section variable?

Post by Yincognito »

jsmorley wrote: June 19th, 2020, 10:40 pm OnUpdateAction=[!SetOption MeterTest Text """#Original#"""]

https://docs.rainmeter.net/manual/skins/option-types/#MagicQuotes



1.jpg
You're the man!! :great: :rosegift:
Didn't think of that - apparently it works for a long string with multiple measure and variable references:

Code: Select all

[!SetOption MT_Rainmeter_TooltipText Text """#LastArtist##CRLF#∆[\x200B] #LastAlbum#[\x200B]#CRLF#≡ #LastTitle##CRLF#● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●#CRLF#Player State    [MS_NowPlaying_State]   ●   Player Volume     [MS_NowPlaying_Volume][\x200B] %[\x200B]#CRLF#Track Length   #LastDuration#   ●   Track Progress    [MS_NowPlaying_Progress][\x200B] %[\x200B]#CRLF#Elapsed Time   [MS_NowPlaying_Position]   ●   Time Left      [MS_Rainmeter_TimeLeft]""" "#ROOTCONFIG#\Tooltip"]
By the way, would this work for the round bracket issue, maybe? :???:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth