-- tells the interpreter that everything on the rest of the line is a comment and to ignore it. Comments help people understand what the code is doing and where.
--g seems to mean the comment was made by Grishnach
if recruitmentUnit.displayText ~= nil then
civ.ui.text(func.splitlines(tostring(recruitmentUnit.displayText)))
Earlier in the code there is a for loop over the table recruitmentUnitTypes. recruitmentUnit was specified to be the name of the "current entry" of recruitmentUnitTypes for the purposes of specifying further instructions.
recruitmentUnit.displayText takes the data "stored in" recruitmentUnit and returns the part of that data "named" displayText.
~= is the "not equal to" operator. It returns true if two things are not equal, and false otherwise. nil is the lua representation of "no data" or "missing data."
if recruitmentUnit.displayText ~= nil then
is the instruction to do all the code between "then" and its corresponding "end" if recruitmentUnit.displayText actually refers to some kind of data.
civ.ui.text(string) prints the string (list of characters) in an in-game text box. You can create a string with double quotes, e.g. "This is a string."
func.splitlines(string) adds newline characters to a string, so that it fits in the in-game text box properly.
tostring(input) turns whatever "input" is to an appropriate string.
Why is the cryptic writing in different lines, avoiding the listing in columns:
When inserting this formating into this post, the text stands in columns:
civ.getUnitType(64).move = 5*multiplier --g Titus Labienus in winter
civ.getUnitType(65).move = 6*multiplier --g Cretan Archers in winter
In my text editor, those particular lines are in a column.
Inserting this formating into this post, shows the 'ends' in columns:
end
end
end
end
end
end
Why are there different free lines between the end-orders? Couldn´t these 'ends' in the lua events file be written one under the other in a column without loosing their function?
Lua ignores "extra" "whitespace," so extra spaces, tabs and newlines don't change how the interpreter uses code.
https://en.wikibooks.org/wiki/Lua_Programming/whitespace
Indentation tends to make code more readable. It is much easier to see what code is in an "if statement" or "for loop" if the code is indented. Some text editors will even anticipate the indentation that you'll want on the next line.
As for the spare lines between the "end" lines, they are probably there because it is easier to write the "end" at the same time as the statement needing the "end," rather than remembering to put it in later, but having it it on the very next line makes the code feel "cluttered" when writing it.
Are you looking at the code in a proper text editor (or lua interpreter)? I think people have recommended notepad++ as one that colours lua code properly. (I use the text editor that comes with Linux Mint, so I can't recommend it to a Windows user.)