Nesting tables in LUA
Posted: 01 Dec 2015, 13:05
Hi guys,
i'm doing a project for my thesis and i'm pretty new to LUA Scripting. My problem is the following: i am trying to track unit-to-unit combat statistics, and i want to obtain a nested table structured this way:
my unit type -> enemy unit type -> distance -> and then the distance table is something like { [100] = 2, [200] = 5, etc} , where indexes 100 200 are different ranges at which my unit has killed enemy unit, and values 2, 5 counts the number of kills have been made at that distance.
The result is intended to give me a statistic on how many times a certain unit type killed that other unit type at different distances, so it is like:
- unit1 x unit2 x 100m = 3
- unit1 x unit2 x 200m = 4
- unit1 x unit4 x 100m = 2
etc
My problem is i can't figure out how to structure this table:
- is there a way to make the "distance" table different for every "my unit x enemy unit" combination? or creating a table "distance" returns always the same table so every kill made at 100m writes on the same "distance" table indipendently of my and enemy unit type?
- the process should be as automatic as possible, meaning i don't want to declare previously all unit types and enemy types as table names or indexes (i can extract "unitDefID" and "attackerDefID" from a .UnitDestroyed call in, so i would like to being able to use that values for defining table values)
Thank you in advance! :)
Fil
i'm doing a project for my thesis and i'm pretty new to LUA Scripting. My problem is the following: i am trying to track unit-to-unit combat statistics, and i want to obtain a nested table structured this way:
my unit type -> enemy unit type -> distance -> and then the distance table is something like { [100] = 2, [200] = 5, etc} , where indexes 100 200 are different ranges at which my unit has killed enemy unit, and values 2, 5 counts the number of kills have been made at that distance.
The result is intended to give me a statistic on how many times a certain unit type killed that other unit type at different distances, so it is like:
- unit1 x unit2 x 100m = 3
- unit1 x unit2 x 200m = 4
- unit1 x unit4 x 100m = 2
etc
My problem is i can't figure out how to structure this table:
- is there a way to make the "distance" table different for every "my unit x enemy unit" combination? or creating a table "distance" returns always the same table so every kill made at 100m writes on the same "distance" table indipendently of my and enemy unit type?
- the process should be as automatic as possible, meaning i don't want to declare previously all unit types and enemy types as table names or indexes (i can extract "unitDefID" and "attackerDefID" from a .UnitDestroyed call in, so i would like to being able to use that values for defining table values)
Thank you in advance! :)
Fil