It is currently July 27th, 2021, 2:55 pm

[BUG?] in Multiple usage of #CURRENTSECTION#

Report bugs with the Rainmeter application and suggest features.
User avatar
death.crafter
Posts: 501
Joined: April 24th, 2021, 8:13 pm

[BUG?] in Multiple usage of #CURRENTSECTION#

Post by death.crafter »

So this is example code:

Code: Select all

[Variables]
;Tween goes from 0 to 1 through lua but you can emulate using action timer if want to
Tween=0

XC=(140-(20*[#Tween])*cos(rad(([#Tween]*360/3)+[&Str:MtrIndx('[#*CURRENTSECTION*]')]*360/3)))
YC=(140-(20*[#Tween])*sin(rad(([#Tween]*360/3)+[&Str:MtrIndx('[#*CURRENTSECTION]*')]*360/3)))

[Shape1]
Meter=Shape
Shape=Ellipse #XC#,#YC#,20,20
Now if I only use XC as a variable and hard code the YC value in Ellipse, it works fine, but if I use both as variables, it doesn't work.

This is what is logged:

Code: Select all

Formula error: (140-(20*[#Tween])*sin(rad(([#Tween]*360/3)+[&Str:MtrIndx('')]*360/3)))
So [&Str:MtrIndx('[#CURRENTSECTION]')] gets the index of a section. Here is the lua function:

Code: Select all

function MtrIndx(k)
    local a=string.gsub(k, '^%D+(%d+)$', '%1')
    a = tonumber(a)
    return a-1
end
I have changed the original code to use meter style but thought would post it since we're having a CURRENTSECTION conundrum after the latest beta.
from the Realm of Death
My Current Desktop
User avatar
Brian
Developer
Posts: 2210
Joined: November 24th, 2011, 1:42 am
Location: Utah

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

Post by Brian »

I think you got a typo.

Code: Select all

YC=(140-(20*[#Tween])*sin(rad(([#Tween]*360/3)+[&Str:MtrIndx('[#*CURRENTSECTION]*')]*360/3)))
Note the asterisk is "outside" the bracket in your original example. Move it to the inside the bracket.

It should be:

Code: Select all

YC=(140-(20*[#Tween])*sin(rad(([#Tween]*360/3)+[&Str:MtrIndx('[#*CURRENTSECTION*]')]*360/3)))
-Brian
User avatar
death.crafter
Posts: 501
Joined: April 24th, 2021, 8:13 pm

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

Post by death.crafter »

Brian wrote: June 27th, 2021, 6:48 am I think you got a typo.

Code: Select all

YC=(140-(20*[#Tween])*sin(rad(([#Tween]*360/3)+[&Str:MtrIndx('[#*CURRENTSECTION]*')]*360/3)))
Note the asterisk is "outside" the bracket in your original example. Move it to the inside the bracket.

It should be:

Code: Select all

YC=(140-(20*[#Tween])*sin(rad(([#Tween]*360/3)+[&Str:MtrIndx('[#*CURRENTSECTION*]')]*360/3)))
-Brian
Sorry the typo was a forum typo. But let me cook an example skin.
from the Realm of Death
My Current Desktop
User avatar
death.crafter
Posts: 501
Joined: April 24th, 2021, 8:13 pm

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

Post by death.crafter »

Brian wrote: June 27th, 2021, 6:48 am
This is the full skin from ActiveColors:


Skin.ini

Code: Select all

[Rainmeter]
Update=1000

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

CalcThis=([MeterExample[#*GET*][#*CURRENTSECTION*][#*INDEX*]:W]+[MeterSample[#*GET*][#*CURRENTSECTION*][#*INDEX*]:W])


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


[MeterExample1]
Meter=String
X=5
Y=30
FontFace=Consolas
FontColor=255,255,255
FontSize=12
AntiAlias=1
Text=Example text

[MeterSample1]
Meter=String
X=5
Y=30
FontFace=Consolas
FontColor=255,255,255
FontSize=12
AntiAlias=1
Text=Sample

[MeasureCalc1]
Measure=Calc
Formula=[#CalcThis]
DynamicVariables=1
#@#Scripts\Script.lua

Code: Select all

function SectionIndex(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
from the Realm of Death
My Current Desktop
User avatar
Brian
Developer
Posts: 2210
Joined: November 24th, 2011, 1:42 am
Location: Utah

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

Post by Brian »

This issue seems to be caused by a recent change a few betas ago (r3452).

Could you try the latest beta and see if this works again?

-Brian
User avatar
death.crafter
Posts: 501
Joined: April 24th, 2021, 8:13 pm

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

Post by death.crafter »

Brian wrote: June 29th, 2021, 6:57 pm This issue seems to be caused by a recent change a few betas ago (r3452).

Could you try the latest beta and see if this works again?

-Brian
No luck🙁
Screenshot 2021-06-30 004236.png
You do not have the required permissions to view the files attached to this post.
from the Realm of Death
My Current Desktop
User avatar
Yincognito
Rainmeter Sage
Posts: 3647
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

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

Post by Yincognito »

Brian wrote: June 29th, 2021, 6:57 pm This issue seems to be caused by a recent change a few betas ago (r3452).
-Brian
The r3493 version seems to have corrected this...

r3445:
r3445.jpg
r3493:
r3493.jpg
You do not have the required permissions to view the files attached to this post.
User avatar
death.crafter
Posts: 501
Joined: April 24th, 2021, 8:13 pm

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

Post by death.crafter »

Yincognito wrote: June 29th, 2021, 11:47 pm The r3493 version seems to have corrected this...
I am afraid not... You can check my log up there
from the Realm of Death
My Current Desktop
User avatar
Active Colors
Moderator
Posts: 807
Joined: February 16th, 2012, 3:32 am
Location: Berlin, Germany

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

Post by Active Colors »

death.crafter wrote: June 29th, 2021, 11:52 pm I am afraid not... You can check my log up there
I am not sure which code you are referring to. It sure did fix the problem, at least the one I described here (thanks Brian!!)https://forum.rainmeter.net/viewtopic.php?f=14&t=36895&start=30#p192448

If it is happening with your code maybe you can pack your skin and attach here? Hopefully it will get resolved too.
User avatar
Yincognito
Rainmeter Sage
Posts: 3647
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, 12:22 am I am not sure which code you are referring to. It sure did fix the problem, at least the one I described here (thanks Brian!!)https://forum.rainmeter.net/viewtopic.php?f=14&t=36895&start=30#p192448

If it is happening with your code maybe you can pack your skin here? Hopefully it will get resolved too.
Yes, it has fixed your skin's problem. It appears to have corrected death.crafter's problem too.

Lua Script:

Code: Select all

function MtrIndx(k)
    local a = string.gsub(k, '^%D+(%d+)$', '%1')
    a = tonumber(a)
    return a-1
end

-- function SectionIndex(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
Skin Code:

Code: Select all

[Variables]
;Tween goes from 0 to 1 through lua but you can emulate using action timer if want to
Tween=0

XC=(140-(20*[#Tween])*cos(rad(([#Tween]*360/3)+[&Script:MtrIndx('[#*CURRENTSECTION*]')]*360/3)))
YC=(140-(20*[#Tween])*sin(rad(([#Tween]*360/3)+[&Script:MtrIndx('[#*CURRENTSECTION*]')]*360/3)))

; XC=(140-(20*[#Tween])*cos(rad(([#Tween]*360/3)+[&Script:SectionIndex('[#*CURRENTSECTION*]','last','(<x>-1)')]*360/3)))
; YC=(140-(20*[#Tween])*sin(rad(([#Tween]*360/3)+[&Script:SectionIndex('[#*CURRENTSECTION*]','last','(<x>-1)')]*360/3)))

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

[Shape1]
Meter=Shape
Shape=Ellipse #XC#,#YC#,20,20
DynamicVariables=1
Test.jpg
Just switch/swap comments in both the script (function vs function) and the skin (XC & YC pair vs XC & YC pair) to compare the results from his implementation vs mine.

That, if I correctly understood what he wanted to do and accurately replicated his code... :confused:

EDIT: It was my mistake earlier, both codes work - edited my rushed reply accordingly. I forgot to change death.crafter's Script measure name to Script instead of Str, so that both scripts can run properly on switching/swapping the comments.
You do not have the required permissions to view the files attached to this post.