What i mean by this is for example i have a table and it is
local thetable = {}
and then it adds stuff into it if something is true but then how would i see if there is anything in the table so that i could do another thing?
What i mean by this is for example i have a table and it is
local thetable = {}
and then it adds stuff into it if something is true but then how would i see if there is anything in the table so that i could do another thing?
function isSomethingInTable(table)
if #table < 1 then
return false
end
return true
end
you would use it like this
local myTable = {}
if not isSomethingInTable(myTable) then
print("there is nothing in my table")
else
print("there is something in my table")
end
Wikipages
If i missunderstod please tell me and ill update my answer
Edit: This works in most cases
It depends on what kind of table it is. Is it a dictionary, mixed, or just string and numbers or maybe just strings or just numbers?
-- strings and numbers or string or numbers
local tab1 = {123456, "string", '123456'}
print(#tab1) -- > 3
-- dictionary
local tab2 = {
this_fun = function()
print('hello')
end;
this_string = true
}
print(#tab2) --> 0
print(tab2[this_string]) --> true
print(tab2['this_fun']()) --> hello
for i,v in pairs(tab2) do
print(i,v)
--> this_fun function #
--> this_string true
end
-- mixed
local tab3 = {
this_fun = function()
end;
this_string = 'string';
123456,
'string';
{anothertable = true}
}
print(#tab3) -- > 3 for the number, string, and nested table
This discussion is preserved as it was. New answers, comments, and votes are closed.