This is a bigger question, but at some point I'd love to pick your brain on the gen.makeArrayOneToN function and re-indexing more generally.
Here's an analogy to understand tables.
Imagine a giant warehouse with lots of shelves to put boxes on, and each of these shelves has a name. At the front of the warehouse, there are some storage lockers. Every function is assigned its own set of lockers (the local variables) that only it can use, but everyone can look inside (or even remove) the boxes on the shelves. You can put 'values' like numbers, strings, unitObjects, etc. into lockers or boxes, one in each locker or box. Crucially, one of the values you can put in a box/locker is
the name of a shelf.
If a function has the name of a shelf, it can do things to that shelf, like adding boxes, changing the contents of existing boxes, or removing boxes. The table constructor instruction {} can be thought of as the program finding an empty shelf, and copying its name (and placing a sticky note telling other programs to get a different empty shelf).
For values like numbers and strings, if I copy them in order to place them in a different locker or box, I'm copying the entire thing. If I change the original, the copy doesn't change. However, in the case of tables (our "shelves" in the above analogy), only the
name is copied, so changing the table in one place effectively changes it everywhere. This is also true for stuff like unitObjects or baseTerrainObjects. If you want a completely new table which has the same structure as the existing one, gen.copyTable can be used (I won't link, since the documentation is wrong at the moment)
Code:
local newCopy = gen.copyTable(originalTable)
Since changing a table changes it everywhere, I can call gen.makeArrayOneToN on a table in order to re-index the integer keys, and I don't have to update the variable containing the table, like I would if I were updating a string or a number. The variable only contains the name of the table, and, since the function has changed the table with that name, the variable is still good as is.