It is currently May 25th, 2019, 2:16 pm

Learning Lua.

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

Learning Lua.

kyriakos876 » September 26th, 2017, 7:24 pm

Hello, I'm trying to learn lua and I have the documentation found at

http://www.lua.org/manual/5.1/manual.html#2.3

but I feel stupid and cannot understand the most simple thing.
I have a variable "C = 0" and an "If" that goes like this:

Code: Select all

If OldVar#C# ~= MyMeasure then
    OldVar#C# == MyMeasure
    C == C+1
End
I want to nest the Variable "C" in the "OldVar" so that I can have OldVar1, OldVar2 etc... but I can't find the correct syntax.
So that it will be

Code: Select all

If OldVar0 ~= MyMeasure then
    OldVar0 == MyMeasure
    C == C+1
End
And after that

Code: Select all

If OldVar1 ~= MyMeasure then
    OldVar1 == MyMeasure
    C == C+1
End
 
etc... Could someone tell me the proper syntax for this?
User avatar
balala
Rainmeter Sage
Posts: 8208
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Learning Lua.

balala » September 26th, 2017, 8:05 pm

In a programming language (what lua is) in such cases the OldVar should be created as an array. You can imagine it as a matrix.
For specific help, please provide us the whole lua code.
User avatar
kyriakos876
Posts: 914
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Learning Lua.

kyriakos876 » September 26th, 2017, 8:40 pm

balala wrote:In a programming language (what lua is) in such cases the OldVar should be created as an array. You can imagine it as a matrix.
For specific help, please provide us the whole lua code.
I hope your eyes are ready for what is coming because I'm sure what I'm doing is awful.

The idea is to create a lua that takes the position of the mouse (at the moment only the X dimension of the mouse) and store them in a list of variables as the mouse moves around, then take those variables and see if they match the equation of a shape, for example circle. That is another part that I will figure out, but now I just want to take those stored variables (OldVar1, OldVar2,....) and manage them with an "If"

(You should hold down control and move the mouse around to write the ones you need.)

I know it's complicated so if you want me to explain something more, tell me.
This is all in order to create gestures while holding down the Control button and moving the mouse around.
Last edited by kyriakos876 on September 29th, 2017, 2:54 pm, edited 1 time in total.
User avatar
jsmorley
Developer
Posts: 19245
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Learning Lua.

jsmorley » September 26th, 2017, 9:59 pm

== is a "comparison", and = is an "assignment". Don't confuse those two.

if SpeedOfLight == 186000 then
GreaterThanThis = 0
end
User avatar
jsmorley
Developer
Posts: 19245
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Learning Lua.

jsmorley » September 26th, 2017, 10:04 pm

These might be better guides:

https://www.lua.org/pil/1.html
https://www.tutorialspoint.com/lua/
http://lua-users.org/wiki/LuaTutorial

The actual Lua manual is pretty sad...
User avatar
kyriakos876
Posts: 914
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Learning Lua.

kyriakos876 » September 26th, 2017, 10:38 pm

jsmorley wrote:These might be better guides:

https://www.lua.org/pil/1.html
https://www.tutorialspoint.com/lua/
http://lua-users.org/wiki/LuaTutorial

The actual Lua manual is pretty sad...
Thanks, I'll try figuring out my problem through those.

Also, I'm aware of the difference between = and == I'm just clueless on when to use each. Sounds stupid but yea... I'm going to dig in now and I'll probably catch up fast.

Expect more stupid questions in the future :D
User avatar
kyriakos876
Posts: 914
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Learning Lua.

kyriakos876 » September 27th, 2017, 2:47 pm

I got many stuff figured out reading those, but now I have a question.

Is it possible to delete a specific row of strings using lua and maybe web parser?
I know you can write on the .ini file using

SKIN:Bang('!WriteKeyValue MeterBox5 "Meter" "Image"')

If the MeterBox5 does not exist it will write it in the end of the .ini file, and I don't even need lua for this, but how can I delete something? Can I?
User avatar
jsmorley
Developer
Posts: 19245
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Learning Lua.

jsmorley » September 27th, 2017, 2:55 pm

kyriakos876 wrote:I got many stuff figured out reading those, but now I have a question.

Is it possible to delete a specific row of strings using lua and maybe web parser?
I know you can write on the .ini file using

SKIN:Bang('!WriteKeyValue MeterBox5 "Meter" "Image"')

If the MeterBox5 does not exist it will write it in the end of the .ini file, and I don't even need lua for this, but how can I delete something? Can I?
You would have to actually open the .ini file and read it as "lines" into an array (a table), then close the file. Then search for and delete the row(s) from the table that matches what you want. Then write out the lines from the table to the file, overwriting what is there, and close it.

This is not terribly hard Lua, some help is here:

https://www.tutorialspoint.com/lua/lua_file_io.htm

But I'm not sure I recommend it. There exists the risk of doing something wrong and losing the skin .ini file entirely. Be sure you make a backup of the file before you start messing with this.
User avatar
kyriakos876
Posts: 914
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Learning Lua.

kyriakos876 » September 27th, 2017, 2:58 pm

More than helpful as always. I appreciate it.
User avatar
jsmorley
Developer
Posts: 19245
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Learning Lua.

jsmorley » September 27th, 2017, 3:00 pm

See here for some more specific help:

https://docs.rainmeter.net/snippets/#FileInputOutput