Answer the question
In order to leave comments, you need to log in
Can an if in lua check for the presence of elements in an array?
Good afternoon, ladies and gentlemen.
Can an if in lua check if values exist in a declared array? In other words, is the code equivalent to:
local currentTable = {}
if currentTable then
local currentTable = {}
if #currentTable ~= 0 then
Answer the question
In order to leave comments, you need to log in
Not equivalent. The code below will check if currentTable exists. if is meaningless because currentTable is declared and exists:
local currentTable = {}
if currentTable then
local currentTable = {}
if #currentTable ~= 0 then
local a = "name"
local currentTable = {a="eman"}
if #currentTable ~= 0 then
function IsEmpty(t)
if not t then
return true
end
for _, _ in pairs(t) do
return false
end
return true
end
local currentTable = {}
if not IsEmpty(currentTable) then
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question