It is currently May 22nd, 2022, 11:24 pm

## Learning Lua.

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

### Learning Lua.

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?
balala
Rainmeter Sage
Posts: 14215
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

### Re: Learning Lua.

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.
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

### Re: Learning Lua.

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.
jsmorley
Developer
Posts: 22519
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

### Re: Learning Lua.

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

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

### Re: Learning Lua.

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...
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

### Re: Learning Lua.

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
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

### Re: Learning Lua.

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?
jsmorley
Developer
Posts: 22519
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

### Re: Learning Lua.

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.
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

### Re: Learning Lua.

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

### Re: Learning Lua.

See here for some more specific help:

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