It is currently September 21st, 2019, 6:09 pm

How can one get a table's length?

Discuss the use of Lua in Script measures.
User avatar
kyriakos876
Posts: 915
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: How can one get a table's length?

kyriakos876 » September 29th, 2017, 2:10 pm

lol okay... I'm going to google more stuff :P
User avatar
dvo
Posts: 541
Joined: February 7th, 2016, 6:08 am

Re: How can one get a table's length?

dvo » September 29th, 2017, 2:11 pm

User avatar
kyriakos876
Posts: 915
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: How can one get a table's length?

kyriakos876 » September 29th, 2017, 2:16 pm

Okay wait a minute... I tried insert and it didn't change the actual code... it just added it "behind the scene" which means if I refresh the skin, the table would be back to normal... how can I write the number? Something like [!WriteKeyValue "Something" "SomethingElse"]
User avatar
jsmorley
Developer
Posts: 19474
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How can one get a table's length?

jsmorley » September 29th, 2017, 2:18 pm

kyriakos876 wrote:Okay wait a minute... I tried insert and it didn't change the actual code... it just added it "behind the scene" which means if I refresh the skin, the table would be back to normal... how can I write the number? Something like [!WriteKeyValue "Something" "SomethingElse"]
You want to change the actual .lua code? No, I'm just not going with you on this entire journey. This is just too much of a Rube Goldberg for my tastes.
User avatar
dvo
Posts: 541
Joined: February 7th, 2016, 6:08 am

Re: How can one get a table's length?

dvo » September 29th, 2017, 2:19 pm

you still missing where in what file....

Code: Select all

[!WriteKeyValue Variables Locale "en_GB" "#@#WXDataWeatherVars.inc"]
User avatar
kyriakos876
Posts: 915
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: How can one get a table's length?

kyriakos876 » September 29th, 2017, 2:20 pm

Ah damn... here I thought this one was going to be easy for a change... Oke... I'll start digging then.
User avatar
kyriakos876
Posts: 915
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: How can one get a table's length?

kyriakos876 » September 29th, 2017, 2:22 pm

dvo wrote:you still missing where in what file....

Code: Select all

[!WriteKeyValue Variables Locale "en_GB" "#@#WXDataWeatherVars.inc"]
yea... it was an incomplete example as I never actually intended to write "SomethingElse" in the "Something" section anyways...
User avatar
jsmorley
Developer
Posts: 19474
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How can one get a table's length?

jsmorley » September 29th, 2017, 2:36 pm

I hate to bail out on you, but I just am going to. I disagree with this effort in principle. There is no good way, no way that I even want to explore, to dynamically change the "contents" of a skin .ini file. Sorry, but no. You can't add and remove meters or measures based on some value you get from some website or something.

There are reasons why this is so.

1) Any attempt to do so is prone to an "endless loop", and while you can very carefully code around that, it creates a hideous Rube Goldberg machine that is then prone to problems if Rainmeter or your PC crashes, or if some end-user using your skin makes some inadvertent or careless change to the code. It's just "fragile".

2) We actively encourage people to encode Rainmeter .ini files as UTF=16 Little Endian. The "New Skin" functionality in Manage does this by default, and I just won't support anything that encourages encoding skin files as ANSI. That can only lead to tears, when users try to use any Unicode or even foreign language characters anywhere in their skin. The upshot of this is that Lua can't read or write to these skin files.

3) While you can use SKIN:Bang('!WriteKeyValue', ... ) in Lua to add or change the value of an option in an existing [Section] in the skin, if you use it to add an entire [Section] to the skin, you have no control over where it is put. It will always be at the very end of the skin .ini file. You can't remove a [Section] or even remove an option, with !WriteKeyValue.

What you want to do is re-think your design. You can certainly have a skin that "adjusts" to different lengths based on some "count" or other result you get from a website or other measure. You need however to design it with some "maximum" number of measures and meters in mind. Start them off all "disabled" and "hidden". Then in your Lua, just "enable" and "unhide" the appropriate measures and meters and update the skin. Still need to be careful about an "endless loop", but a little thought can solve that.

You might get there with the way you are going, but it kinda makes my skin crawl... Good luck with it.
User avatar
kyriakos876
Posts: 915
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: How can one get a table's length?

kyriakos876 » September 29th, 2017, 2:53 pm

jsmorley wrote:I hate to bail out on you, but I just am going to. I disagree with this effort in principle. There is no good way, no way that I even want to explore, to dynamically change the "contents" of a skin .ini file. Sorry, but no. You can't add and remove meters or measures based on some value you get from some website or something.

There are reasons why this is so.

1) Any attempt to do so is prone to an "endless loop", and while you can very carefully code around that, it creates a hideous Rube Goldberg machine that is then prone to problems if Rainmeter or your PC crashes, or if some end-user using your skin makes some inadvertent or careless change to the code. It's just "fragile".

2) We actively encourage people to encode Rainmeter .ini files as UTF=16 Little Endian. The "New Skin" functionality in Manage does this by default, and I just won't support anything that encourages encoding skin files as ANSI. That can only lead to tears, when users try to use any Unicode or even foreign language characters anywhere in their skin. The upshot of this is that Lua can't read or write to these skin files.

3) While you can use SKIN:Bang('!WriteKeyValue', ... ) in Lua to add or change the value of an option in an existing [Section] in the skin, if you use it to add an entire [Section] to the skin, you have no control over where it is put. It will always be at the very end of the skin .ini file. You can't remove a [Section] or even remove an option, with !WriteKeyValue.

You might get there... Good luck with it.
1) I knew you weren't with me on this from the moment you told me to, and I don't intend releasing any skin that, if edited, could lead to a Rainmeter or PC crash. (Actually I'm going to delete any skins I posted on previous threads now that you mentioned it.)

2)The skin I'm writing/deleting on, is encoded to UTF-8-BOM. Not just ANSI...

3)At the moment, I can have

LeftMouseUpAction=[!WriteKeyValue "--" "NewNumber" "2" "#@#SLua.lua"]

which comments out the right bracket but leaves me with an open bracket, so I'm trying to bypass that or I'll just make another script that deletes this line entirely if I don't figure it out.
User avatar
jsmorley
Developer
Posts: 19474
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How can one get a table's length?

jsmorley » September 29th, 2017, 2:57 pm

Rainmeter is going to have huge issues with skin .ini files encoded as UTF-8 w/BOM. They are just not going to work right, as Rainmeter can't properly read the .ini file.

What Rainmeter supports is:

UTF-16 Little Endian (recommended)
ANSI (can't have any Unicode in it)
UTF-8 without BOM (can't have any Unicode in it, or it just automatically becomes UTF-8 with BOM, which won't work)