Code: Select all
DeletedBoxes = {2, 9, 14, 3, 8}
local NumberOflistElements = 0
local count = 0
while DeletedBoxes[count] ~= nil do
count = count + 1
end
NumberOflistElements = count
Code: Select all
DeletedBoxes = {2, 9, 14, 3, 8}
local NumberOflistElements = 0
local count = 0
while DeletedBoxes[count] ~= nil do
count = count + 1
end
NumberOflistElements = count
Yes.kyriakos876 wrote:Hello, I was wondering why does this not work. I want to get the length of the "DeletedBoxes " table using this:
Is there any function already in lua that does it like other languages?Code: Select all
DeletedBoxes = {2, 9, 14, 3, 8} local NumberOflistElements = 0 local count = 0 while DeletedBoxes[count] ~= nil do count = count + 1 end NumberOflistElements = count
Code: Select all
DeletedBoxes = {2, 9, 14, 3, 8}
NumberOflistElements = #DeletedBoxes
Knowledge is power. Thanks againjsmorley wrote:Yes.
Code: Select all
DeletedBoxes = {2, 9, 14, 3, 8} NumberOflistElements = #DeletedBoxes
That seems unnecessary to exist when you can do it with just a hashtag... Though I'm new and I can't imagine of a reason so yea... Imma stay with the hashtagjsmorley wrote:You can also use table.getn() to retrieve the size of a table. The "#" char is more or less a shortcut to that.
]
Code: Select all
DeletedBoxes = {2, 3, 5, 6}
NumberOflistElements = #DeletedBoxes
DeletedBoxes[NumberOflistElements+1] = 9
kyriakos876 wrote:Okay, now an actual question.
How can I add a new thing after the table's last element?
I have this that adds the number 9 after the last element, but how can I save it in the lua?Code: Select all
DeletedBoxes = {2, 3, 5, 6} NumberOflistElements = #DeletedBoxes DeletedBoxes[NumberOflistElements+1] = 9
(Then I suppose to do that with a number that came from an .ini file I just call the function with this number right?)
Code: Select all
DeletedBoxes = {2, 3, 5, 6}
NumberOflistElements = #DeletedBoxes
table.insert(DeletedBoxes, #DeletedBoxes, 9)
Code: Select all
DeletedBoxes = {2, 3, 5, 6}
NumberOflistElements = #DeletedBoxes
table.insert(DeletedBoxes, 9)