Page 5 of 5
Re: [Suggestion] Assigning a number to a meter
Posted: June 27th, 2021, 7:15 am
by Active Colors
death.crafter wrote: ↑June 27th, 2021, 4:49 am
I may be thrown off a bit here. Is
[#*GET*][#*CURRENTSECTION*][#*INDEX*] a way to get the index of a section? I'm pretty sure it is not.
It is. Yincognito has created a way to do this. The working example is here
https://forum.rainmeter.net/viewtopic.php?f=14&t=36895&start=30#p190373.
Re: [Suggestion] Assigning a number to a meter
Posted: June 27th, 2021, 7:42 am
by death.crafter
You did not mention the GET and INDEX variables. Anyway, I already have a thread opened about it.
https://forum.rainmeter.net/viewtopic.php?f=14&t=37775
Can you post your example skin in there? I actually changed my skin to the point of no return. I will make another example tho when I am free later.
Thanks,
death.crafter
Re: [Suggestion] Assigning a number to a meter
Posted: June 27th, 2021, 8:08 am
by Active Colors
death.crafter wrote: ↑June 27th, 2021, 7:42 am
You did not mention the GET and INDEX variables. Anyway, I already have a thread opened about it.
https://forum.rainmeter.net/viewtopic.php?f=14&t=37775
Can you post your example skin in there? I actually changed my skin to the point of no return. I will make another example tho when I am free later.
Thanks,
death.crafter
Interesting that we decided to post about it simultaneously. I noticed the problem earlier but didn't decide to post it right away. The problem appeared not in the last beta though but several betas earlier (if the causes to our problem are absolutely the same).
This is the full skin:
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
Re: [Suggestion] Assigning a number to a meter
Posted: June 27th, 2021, 10:44 am
by Yincognito
death.crafter wrote: ↑June 27th, 2021, 7:42 am
You did not mention the GET and INDEX variables. Anyway, I already have a thread opened about it.
https://forum.rainmeter.net/viewtopic.php?f=14&t=37775
Can you post your example skin in there? I actually changed my skin to the point of no return. I will make another example tho when I am free later.
Thanks,
death.crafter
Yeah, using the GET and INDEX variables was done out of necessity, since using a single CURRENTSECTIONINDEX like variable had drawbacks due to how Rainmeter operates and the tricky nature of #CURRENTSECTION# overall, which is not necessarily related to the last betas.
I would have loved this to be straightforward, but as you can see, it is not, and there aren't many things us users can do about it, unfortunately... which is a pity since otherwise the codes are correct.
Re: [Suggestion] Assigning a number to a meter
Posted: June 27th, 2021, 11:34 am
by death.crafter
Yincognito wrote: ↑June 27th, 2021, 10:44 am
Yeah, using the GET and INDEX variables was done out of necessity, since using a single CURRENTSECTIONINDEX like variable had drawbacks due to how Rainmeter operates and the tricky nature of #CURRENTSECTION# overall, which is not necessarily related to the last betas.
I would have loved this to be straightforward, but as you can see, it is not, and there aren't many things us users can do about it, unfortunately... which is a pity since otherwise the codes are correct.
Actually I was using this thing from a long time. But my lua is something like:
Code: Select all
function Indx(k)
local a=string.gsub(k, '^%D+(%d+)$', '%1')
a = tonumber(a) -- just in case I have to do arithmetic operations
return a
end
Yours has a broad range of use. But I tend to keep things short so I just use [&Str:Indx('[#CURRENTSECTION]')] (I am lazy like hell lol).
Re: [Suggestion] Assigning a number to a meter
Posted: June 27th, 2021, 11:59 am
by Yincognito
death.crafter wrote: ↑June 27th, 2021, 11:34 am
Actually I was using this thing from a long time. But my lua is something like:
Code: Select all
function Indx(k)
local a=string.gsub(k, '^%D+(%d+)$', '%1')
a = tonumber(a) -- just in case I have to do arithmetic operations
return a
end
Yours has a broad range of use. But I tend to keep things short so I just use [&Str:Indx('[#CURRENTSECTION]')] (I am lazy like hell lol).
Haha, yes, I also like to shorten things up (you could have written just
[&S:Idx()], by the way), but I made this from the start with the idea to improve
Jeff's version and solve a wide range of instances where one would need such an index once and for all, so it had to be something that everyone would understand - after all,
[&Script:SectionIndex()] is not that long.
Too bad there were these hickups along the way, because otherwise everything should have worked smoothly right from the start and in
any circumstance (which was one of my goals, hence the "formula" thing, no dependency on
SKIN:GetMeasure() or
SKIN:GetMeter(), any occurrence of an index covered, etc).
By the way, I suppose your version doesn't work either if you try to make a custom variable out of it and use it like ActiveColors tried to, right?
Re: [Suggestion] Assigning a number to a meter
Posted: June 27th, 2021, 12:23 pm
by death.crafter
Yincognito wrote: ↑June 27th, 2021, 11:59 am
By the way, I suppose your version doesn't work either if you try to make a custom variable out of it and use it like ActiveColors tried to, right?
I guess the issue is comes with a specific case, which is rather hard to diagnose.
But Active Color's case is closer to mine. He tried to use both inlines in a single variable while I use two variables. But we both got errors. So I guess it's an error with [#CURRENTSECTION] and inline lua.
And I noticed another odd thing. If you put a non English alphabet character like
ī, in a folder name, anywhere in the path of a lua file, for example root config name as
Materiarusuīto, functions like
os.clock() don't work at all ,returning null values.
If there isn't a valid reason for this I will make a separate thread.
Re: [Suggestion] Assigning a number to a meter
Posted: June 27th, 2021, 2:33 pm
by Yincognito
death.crafter wrote: ↑June 27th, 2021, 12:23 pmSo I guess it's an error with [#CURRENTSECTION] and inline lua.
Unless you refer to issues specific to latest betas, there is no error like that, since plain inline syntax works every time, e.g.:
Code: Select all
Formula=([MeterExample[&Script:SectionIndex('[#CURRENTSECTION]','last','(<x>)')]:W]+[MeterSample[&Script:SectionIndex('[#CURRENTSECTION]','last','(<x>)')]:W])
It's more a problem with
#CURRENTSECTION# and escaping / nesting / formulas / inclusion in other variables. Inline Lua has no business with
#CURRENTSECTION# at all, because it's only the actual string (i.e. section name) that
#CURRENTSECTION# refers to which is passed to Lua. If Rainmeter itself can't properly parse or replace
#CURRENTSECTION# with the actual string, Lua will naturally get nothing and fail as well.
Re: [Suggestion] Assigning a number to a meter
Posted: July 3rd, 2021, 11:10 am
by Yincognito
For the record, extracting a current section's index (or of any - altered or not - index occurence of any section, for that matter) is possible now by using a Rainmeter version greater than 4.4.0.3493 (due to the fix mentioned
here) and a Lua function similar to the one presented earlier in this thread
here.