Page 1 of 1

It makes no sense[solved]

Posted: Mon Feb 27, 2023 4:09 am
by zalander
Hi,
Today I was working on my code but when I executed it gave me a strange error:

Code: Select all

--the error
Error

Syntax error: libs/sav.lua:16: '=' expected near 'love'



Traceback

[love "callbacks.lua"]:228: in function 'handler'
[C]: at 0x7ffeecd331d0
[C]: in function 'require'
main.lua:3: in function 'load'
[love "callbacks.lua"]:136: in function <[love "callbacks.lua"]:135>
[C]: in function 'xpcall'
[C]: in function 'xpcall'
here is the code:

Code: Select all

l = {}
function l.load(file)
    if love.filesystem.getInfo(file) then
        return(love.filesystem.read(file))
    else
        love.filesystem.newFile(file)
        love.filesystem.write(file, 0)
        return(love.filesystem.read(file))
    end
end
function l.save(val, file)
    if love.filesystem.getInfo(file) then
        love.filesystem.write(file, val)
    else
        l.load
        love.filesystem.write(file, val)
    end
end
Hope you guys will help me !

Re: It makes no sense

Posted: Mon Feb 27, 2023 6:28 am
by Andlac028
You are missing () on previous line (before l.load), so Lua thinks, you want tonassign some value to l.load, and that’s why it wants =. In some languages, it is valid to call function like that, but in lua, you have ti call it in one of following ways:

Code: Select all

func() -- normal call
func{} -- direct table parameter (you can give only first parameter this way)
func”” -- direct string parameter (you can give only first parameter this way)

Re: It makes no sense

Posted: Tue Feb 28, 2023 2:36 am
by zalander
Ohhhhh I get it now thanks ! :awesome: