Page 1 of 2
why am i getting this error?
Posted: Tue Jul 20, 2021 6:10 pm
by RocketSocketGames
im getting a strange error when i try to make a variables' value go up. it says
Code: Select all
Error
Syntax error: main.lua:6: '=' expected near '+'
Traceback
[C]: at 0x52f6d550
[C]: in function 'require'
[C]: in function 'xpcall'
[C]: in function 'xpcall'
but when i actually put it near '+' this happens!
Code: Select all
Error
Syntax error: main.lua:6: unexpected symbol near '+'
Traceback
[C]: at 0x52f6d550
[C]: in function 'require'
[C]: in function 'xpcall'
[C]: in function 'xpcall'
heres the code im using:
Code: Select all
count = 0
function love.draw()
love.graphics.print(count, 400, 150)
end
function love.keyboard.isDown(space)
count + 1
end
Re: why am i getting this error?
Posted: Tue Jul 20, 2021 8:18 pm
by darkfrei
https://love2d.org/wiki/love.keypressed
Code: Select all
function love.keypressed( key, scancode, isrepeat )
if scancode == "space" then
count = count + 1
end
end
The isDown must be called from update (or draw).
Re: why am i getting this error?
Posted: Tue Jul 20, 2021 8:28 pm
by RocketSocketGames
darkfrei wrote: ↑Tue Jul 20, 2021 8:18 pmCode: Select all
function love.keyboard.keypressed( key, scancode, isrepeat )
if scancode == "space" then
count = count + 1
end
end
that doesnt work. when i press space. the printed number doesnt update.
edit: and heck, when i reuse the code on a different project, it doesnt even work at all!
Re: why am i getting this error?
Posted: Tue Jul 20, 2021 8:35 pm
by GVovkiv
You misspelled little ("love.keypressed" instead "love.keyboard.keypressed"):
Code: Select all
count = 0
function love.draw()
love.graphics.print(count, 400, 150)
end
function love.keypressed( key, scancode, isrepeat )
if scancode == "space" then
count = count + 1
end
end
Re: why am i getting this error?
Posted: Tue Jul 20, 2021 8:42 pm
by RocketSocketGames
GVovkiv wrote: ↑Tue Jul 20, 2021 8:35 pmYou misspelled little
thats the most random thing to say. because none of us said "little"
Re: why am i getting this error?
Posted: Tue Jul 20, 2021 8:44 pm
by GVovkiv
also
Code: Select all
count = 0
function love.draw()
love.graphics.print(count, 400, 150)
end
function love.keyboard.isDown(space) -- isDown needs string as argument, but you send it variable space (which in that case == nil), not string "space"
count + 1 -- lua doesn't support "=+", "=-", etc; only value = value + 1
end -- also, "love.keyboard.isDown()" it's not callback, it should be used in conditions:
love.update = function()
if love.keyboard.isDown("space") then
*something*
end
end
Re: why am i getting this error?
Posted: Tue Jul 20, 2021 8:45 pm
by GVovkiv
RocketSocketGames wrote: ↑Tue Jul 20, 2021 8:42 pm
GVovkiv wrote: ↑Tue Jul 20, 2021 8:35 pmYou misspelled little
thats the most random thing to say. because none of us said "little"
ok, cool
just use "love.keypressed()" instead of "love.keyboard.keypressed()" ok?
Re: why am i getting this error?
Posted: Tue Jul 20, 2021 9:00 pm
by pgimeno
Not everyone's first language is English.
I think GVovkiv meant "You made a little misspelling".
Re: why am i getting this error?
Posted: Tue Jul 20, 2021 9:05 pm
by darkfrei
pgimeno wrote: ↑Tue Jul 20, 2021 9:00 pm
Not everyone's first language is English.
I think GVovkiv meant "You made a little misspelling".
You have misspelled a little bit
Re: why am i getting this error?
Posted: Tue Jul 20, 2021 9:12 pm
by GVovkiv
pgimeno wrote: ↑Tue Jul 20, 2021 9:00 pm
Not everyone's first language is English.
I think GVovkiv meant "You made a little misspelling".
Yeah, thanks