why am i getting this error?

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.
User avatar
RocketSocketGames
Prole
Posts: 8
Joined: Tue Jul 20, 2021 5:51 pm

why am i getting this error?

Post 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
Ha, i totally know lua!
User avatar
darkfrei
Party member
Posts: 1168
Joined: Sat Feb 08, 2020 11:09 pm

Re: why am i getting this error?

Post by darkfrei »

RocketSocketGames wrote: Tue Jul 20, 2021 6:10 pm

Code: Select all

function love.keyboard.isDown(space)
	count + 1
end
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).
Last edited by darkfrei on Tue Jul 20, 2021 8:53 pm, edited 1 time in total.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
RocketSocketGames
Prole
Posts: 8
Joined: Tue Jul 20, 2021 5:51 pm

Re: why am i getting this error?

Post by RocketSocketGames »

darkfrei wrote: Tue Jul 20, 2021 8:18 pm

Code: 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!
Ha, i totally know lua!
User avatar
GVovkiv
Party member
Posts: 668
Joined: Fri Jan 15, 2021 7:29 am

Re: why am i getting this error?

Post by GVovkiv »

darkfrei wrote: Tue Jul 20, 2021 8:18 pm
RocketSocketGames wrote: Tue Jul 20, 2021 6:10 pm

Code: Select all

function love.keyboard.isDown(space)
	count + 1
end
https://love2d.org/wiki/love.keypressed

Code: Select all

function love.keyboard.keypressed( key, scancode, isrepeat )
	if scancode == "space" then
		count = count + 1
	end
end
The isDown must be called from update (or draw).
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
Last edited by GVovkiv on Tue Jul 20, 2021 8:49 pm, edited 1 time in total.
User avatar
RocketSocketGames
Prole
Posts: 8
Joined: Tue Jul 20, 2021 5:51 pm

Re: why am i getting this error?

Post 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"
Ha, i totally know lua!
User avatar
GVovkiv
Party member
Posts: 668
Joined: Fri Jan 15, 2021 7:29 am

Re: why am i getting this error?

Post 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

Last edited by GVovkiv on Tue Jul 20, 2021 8:48 pm, edited 3 times in total.
User avatar
GVovkiv
Party member
Posts: 668
Joined: Fri Jan 15, 2021 7:29 am

Re: why am i getting this error?

Post 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?
User avatar
pgimeno
Party member
Posts: 3541
Joined: Sun Oct 18, 2015 2:58 pm

Re: why am i getting this error?

Post by pgimeno »

Not everyone's first language is English.

I think GVovkiv meant "You made a little misspelling".
User avatar
darkfrei
Party member
Posts: 1168
Joined: Sat Feb 08, 2020 11:09 pm

Re: why am i getting this error?

Post 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 :)
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
GVovkiv
Party member
Posts: 668
Joined: Fri Jan 15, 2021 7:29 am

Re: why am i getting this error?

Post 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
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 16 guests