AdmiralCloack.lua: 54: 'then' expected near ')'

2
function Cloaks:Init()
    if (file_exists)(Cloaks.DB) == false) then
        print('Creating Admiral Cloak Database')
        table.save({},Cloaks.DB, FILE_WRITE)
    end
end

    
asked by DarkRulez 10.09.2017 в 17:35
source

4 answers

2

The error is in your if, assuming everything else is fine, it should be like this

function Cloaks:Init()
    if ((file_exists)(Cloaks.DB)) == false) then
        print('Creating Admiral Cloak Database')
        table.save({},Cloaks.DB, FILE_WRITE)
    end
end

you were missing parentheses

    
answered by 10.09.2017 в 17:40
0

according to link the if statement does not need parentheses:

if a<0 then a = 0 end

your code would be like this:

function Cloaks:Init()
    if (file_exists)(Cloaks.DB) == false then
        print('Creating Admiral Cloak Database')
        table.save({},Cloaks.DB, FILE_WRITE)
    end
end
    
answered by 10.09.2017 в 18:46
0

trying to understand a bit the conditional logic if in your post, it should be clarified that if you do in Lua the following:

print((true)(true)) -- asumo que deseas hacer una especie de multiplicación en lugar del operador lógico and

You will get an error, I think the solution could go like this:

local file_exists = "existeArchivo"
local Cloaks = {}

-- Cloaks.DB -- no definido o nil
Cloaks.Init = function()
  if not (file_exists and Cloaks.DB) then print("¡listo!") end
end

Cloaks.Init() -- se imprime: ¡listo!

Note that Lua considers a null or false variable to be false, this can be confusing because it could even be believed in the first instance that an empty table is null which is not true for Lua

if {} then print("verdad") end -- se imprime: verdad
    
answered by 29.05.2018 в 19:09
0

if you put it that way?

if((file_exists(Cloaks.DB)) == false) then
    
answered by 29.05.2018 в 19:24