It is currently March 28th, 2024, 12:10 pm

[BUG?] in Multiple usage of #CURRENTSECTION#

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

Re: [BUG?] in Multiple usage of #CURRENTSECTION#

Post by Yincognito »

death.crafter wrote: June 30th, 2021, 3:12 pm You think so? I beg to differ.

While with

Code: Select all

[Variables]
Text=[#*CURRENTSECTION*]

[String]
Text=[#Text]
it displays String but with

Code: Select all

[Variables]
Text=#*CURRENTSECTION*#

[String]
Text=[#Text]
it displays #CURRENTSECTION#.

And it's not used in a bang.
Of course it would, after all, you are escaping CURRENTSECTION, and your code is equivalent to the literal:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

---Meters---

[String]
Meter=String
Text=#*CURRENTSECTION*#
FontSize=14
SolidColor=00ffff
AntiAlias=1
DynamicVariables=1
What you're looking for is something along these lines:

Code: Select all

[Variables]
Text=CURRENTSECTION

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

---Meters---

[String]
Meter=String
Text=[#[#Text]]
FontSize=14
SolidColor=00ffff
AntiAlias=1
DynamicVariables=1
which will display "String" as desired. Yeah, I know, it's a bit difficult to make those replacements in the mind, but I believe I'm right with this. Correct me if you think otherwise though.
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm
Contact:

Re: [BUG?] in Multiple usage of #CURRENTSECTION#

Post by death.crafter »

Yincognito wrote: June 30th, 2021, 3:47 pm Of course it would, after all, you are escaping CURRENTSECTION, and your code is equivalent to the literal:

which will display "String" as desired. Yeah, I know, it's a bit difficult to make those replacements in the mind, but I believe I'm right with this. Correct me if you think otherwise though.
S**t... I am a dork lol... Nvm
Last edited by Brian on July 3rd, 2021, 6:52 am, edited 1 time in total.
Reason: Language.
User avatar
Yincognito
Rainmeter Sage
Posts: 7017
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: [BUG?] in Multiple usage of #CURRENTSECTION#

Post by Yincognito »

Active Colors wrote: June 30th, 2021, 3:27 pm Ah yeah, fair enough, this is unbeatable :D

Off-topic:

First of all I am thinking to reduce it down to #INDEX# just like death.crafter has done to make it shorter and faster to read :D

The Buffer method is actually very similar to what I've done before with faking a bang https://forum.rainmeter.net/viewtopic.php?f=14&t=36895&start=30#p190370

I have been trying to weight which way to use as well. So far it is:

either Buffer method:

Code: Select all

[Variables]
Buffer=
INDEX=[&CSI:SectionIndex('[#*Buffer*]','last','(<x>)')]
!Buffer=!SetVariable Buffer

[Meter]
MouseOverAction=[#!Buffer# #CURRENTSECTION#][!Log #INDEX#]
or Split method:

Code: Select all

[Variables]
GET=[&CSI:SectionIndex('
INDEX=','last','(<x>)')]

[Meter]
MouseOverAction=[!Log "[#GET][#CURRENTSECTION][#INDEX]"]
Exactly. Actually, it's the variable that should be named CSI (since it's pretty particular to this "current section index" case), while the Script measure (and, why not, its Lua function as well) can be named, say, SI (aka "section index"):

Code: Select all

[Variables]
...
CSI=[&SI:SI('[#*Buffer*]','last','(<x>)')]
...
Same with the Split method. Unfortunately, there you can abbreviate CURRENTSECTION - and neither in the other variants. If you try to, you have to escape it, and you'd be back to square one, LOL.
User avatar
Yincognito
Rainmeter Sage
Posts: 7017
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: [BUG?] in Multiple usage of #CURRENTSECTION#

Post by Yincognito »

death.crafter wrote: June 30th, 2021, 4:09 pm S**t... I am a dork lol... Nvm
No, you're not. It happens. ;-)
User avatar
Active Colors
Moderator
Posts: 1251
Joined: February 16th, 2012, 3:32 am
Location: Berlin, Germany
Contact:

Re: [BUG?] in Multiple usage of #CURRENTSECTION#

Post by Active Colors »

death.crafter wrote: June 30th, 2021, 3:12 pm You think so? I beg to differ.

While with

Code: Select all

[Variables]
Text=[#*CURRENTSECTION*]

[String]
Text=[#Text]
it displays String but with

Code: Select all

[Variables]
Text=#*CURRENTSECTION*#

[String]
Text=[#Text]
it displays #CURRENTSECTION#.

And it's not used in a bang.
Nested variables go through more work on each update than normal variables. I think nested variables go through additional "post-parsing" process which is why it works when nested form is used.
User avatar
Yincognito
Rainmeter Sage
Posts: 7017
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: [BUG?] in Multiple usage of #CURRENTSECTION#

Post by Yincognito »

Good idea. I'd like to make a suggestion to the same devs to add / correct some notes in the manual regarding #CURRENTSECTION#, making clear that for the time being, its value is NOT accessible in bangs (native or Lua style) unless used LITERALLY. Variables containing the escaped form of #CURRENTSECTION# won't work in bangs.
User avatar
Yincognito
Rainmeter Sage
Posts: 7017
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: [BUG?] in Multiple usage of #CURRENTSECTION#

Post by Yincognito »

Active Colors wrote: June 30th, 2021, 3:27 pmFirst of all I am thinking to reduce it down to #INDEX# just like death.crafter has done to make it shorter and faster to read :D
To conclude it, you can't get shorter than this...
@Resources\SI.lua:

Code: Select all

function SI(section, occurrence, formula)
  local indexes = {}
  for index in section:gmatch('%d+') do table.insert(indexes, index) end
  if occurrence == 'first' then occurrence = 1 elseif occurrence == 'last' then occurrence = #indexes end
  return tostring(SKIN:ParseFormula(string.gsub(formula, '<x>', tostring(indexes[tonumber(occurrence)] or '0')))) or '0'
end
[SkinFolder]\SI.ini:

Code: Select all

[Variables]

; Lua Way - Inline method:
; [&SI:SI('[#CURRENTSECTION]','last','(<x>)')]

; Old Way - Splits method:
G=[&SI:SI('
I=','last','(<x>)')]

; New Way - Buffer method:
V=!SetVariable X
P=[&SI:SI('[#*CURRENTSECTION*]','last','(<x>)')]
B=[&SI:SI('[#*X*]','last','(<x>)')]

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

---Measures---

[SI]
Measure=Script
ScriptFile=#@#SI.lua
UpdateDivider=-1
DynamicVariables=1

; Variables =   0 chars, Measures = 450 chars, Total = 450 chars
[LuaMeasureBlah7Blah15Blah3]
Measure=Calc
Formula=([&SI:SI('[#CURRENTSECTION]','last','(<x>)')])
UpdateDivider=-1
IfCondition=([&SI:SI('[#CURRENTSECTION]','last','(<x>)')]=3)
IfTrueAction=[!Log "Last index of [#CURRENTSECTION] (i.e. [&SI:SI('[#CURRENTSECTION]','last','(<x>)')]) equals 3"]
IfFalseAction=[!Log "Last index of [#CURRENTSECTION] (i.e. [&SI:SI('[#CURRENTSECTION]','last','(<x>)')]) equals 3"]
IfConditionMode=1
DynamicVariables=1

; Variables =  33 chars, Measures = 374 chars, Total = 407 chars
[OldMeasureBlah7Blah15Blah3]
Measure=Calc
Formula=([#G][#CURRENTSECTION][#I])
UpdateDivider=-1
IfCondition=([#G][#CURRENTSECTION][#I]=3)
IfTrueAction=[!Log "Last index of [#CURRENTSECTION] (i.e. [#G][#CURRENTSECTION][#I]) equals 3"]
IfFalseAction=[!Log "Last index of [#CURRENTSECTION] (i.e. [#G][#CURRENTSECTION][#I]) equals 3"]
IfConditionMode=1
DynamicVariables=1

; Variables = 103 chars, Measures = 310 chars, Total = 413 chars
[NewMeasureBlah7Blah15Blah3]
Measure=Calc
Formula=([#P])
UpdateDivider=-1
IfCondition=([#P]=3)
IfTrueAction=[#V# [#CURRENTSECTION]][!Log "Last index of [#X] (i.e. [#B]) equals 3"]
IfFalseAction=[#V# [#CURRENTSECTION]][!Log "Last index of [#X] (i.e. [#B]) equals 3"]
IfConditionMode=1
DynamicVariables=1

---Meters---

[MeterResult]
Meter=String
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=LuaMeasureBlah7Blah15Blah3
MeasureName2=OldMeasureBlah7Blah15Blah3
MeasureName3=NewMeasureBlah7Blah15Blah3
Text="Results:#CRLF#Lua method = %1#CRLF#Old method = %2#CRLF#New method = %3"
DynamicVariables=1
Working Methods Comparison.jpg
I reduced things to either 1 or 2 capital letters, in order to be fair with every approach that works. :bow: The Total Chars value indicates the winner. :D

If it's not enough, here's something you probably didn't anticipate: you can't use the !SetVariable bang in regular measure options, like Formula and such, so you must create another variable to set things up there the "plain" (aka P) way, while in bangs you must use your "bang" (aka B) way, along with setting the "variable" (aka V) holding the current section. This reduces the chars needed for the measure / meter (by the way, I didn't use your buffer approach in the meter yet), but increases the chars needed for the variables, not to mention it can create confusion between the P and B ways, along with requiring creating new variables for hypothetical arbitrary section names (other than the current section) you might want to get the index from. Well, in your buffer approach' defense, you only need to create / write those variable once, but then, so needs my split approach too, and only for changes in the occurrence or index formula (unless I split the #I# further, that is).

This is how simplifying things becomes complicating them, when one doesn't have all the tools working. :confused: It's possible that your code will become like my regexes you quoted in another thread, and then it will be my time to meme your ways... :lol:
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm
Contact:

Re: [BUG?] in Multiple usage of #CURRENTSECTION#

Post by death.crafter »

Yincognito wrote: June 30th, 2021, 8:22 pm To conclude it, you can't get shorter than this...
LMAO...

Now this defies the most sacred and foremost law of declaring a variable name. They should convey what they are used for.

But then again, the more short it is, the more easier for us
, and the more harder for our next generation who want to dissect our code.
User avatar
Yincognito
Rainmeter Sage
Posts: 7017
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: [BUG?] in Multiple usage of #CURRENTSECTION#

Post by Yincognito »

death.crafter wrote: June 30th, 2021, 9:09 pm LMAO...

Now this defies the most sacred and foremost law of declaring a variable name. They should convey what they are used for.

But then again, the more short it is, the more easier for us
, and the more harder for our next generation who want to dissect our code.
Well, ActiveColors wanted short stuff, I gave him what he wanted... :lol:

Other than that, who cares what they are used for? The next generation already cares only whether things look nice, even less whether they work, and almost no concern for the "essence", so, no problem for a civilization of consumers... :???:
P.S. Maybe you didn't see this. Pretend you don't know who's the author. :sly:
Post Reply