It makes no sense[solved]

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
zalander
Citizen
Posts: 76
Joined: Mon Jan 09, 2023 5:58 am
Location: India
Contact:

It makes no sense[solved]

Post 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 !
Last edited by zalander on Tue Feb 28, 2023 2:37 am, edited 1 time in total.
Using LOVE to make everything except games :crazy:

Code: Select all

astring = "pog"
print(astring)
--pog
Andlac028
Party member
Posts: 174
Joined: Fri Dec 14, 2018 2:27 pm
Location: Slovakia

Re: It makes no sense

Post 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)
User avatar
zalander
Citizen
Posts: 76
Joined: Mon Jan 09, 2023 5:58 am
Location: India
Contact:

Re: It makes no sense

Post by zalander »

Ohhhhh I get it now thanks ! :awesome:
Using LOVE to make everything except games :crazy:

Code: Select all

astring = "pog"
print(astring)
--pog
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests