A few simple lua questions I'd like to understand
I found these lua snippets in Kettenkrad's Artillery L-GED mod and I want to understand them better.
Code:
function Create(self)
print("C-4 detonated!");
if c4ListD ~= nil then
for i=1,#c4ListD do
if MovableMan:IsParticle(c4ListD[i]) then
c4ListD[i]:GibThis();
end
end
end
c4ListD = { };
end
Code:
function Create(self)
print("C-4 planted!");
if c4ListD == nil then
c4ListD = { };
end
c4ListD[#c4ListD + 1] = self;
self.LTimer = Timer();
end
They seem fairly simple, but there are a few variables I don't understand and which I failed to find in the wiki.
1.
c4ListD - I assume that "c4" can be replaced by any other object in the game, but what does "ListD" represent? I also assume that "#c4ListD" just turns the object into a number?
2.
i=1 - What does "i" represent? It seems to be more than just a randomly defined value, since I remember seeing lua scripts using "i" quite a lot.
3.
c4ListD[i] - so if "i=1", this is the same as "c4ListD[1]"?
4.
c4ListD = { } - What do the empty brackets represent?
5. Is there any functional purpose in the line"
Code:
print("C-4 detonated!")
other than printing out a line which says "C-4 detonated!"?
(I mean, if I get rid of this line, will anything happen to the script that will make it unable to run properly?)
Thanks for any help.