As a complete beginner I'm experimenting on a small code on Pico-8 :
function _update()
if p.x, p.y == 64, 45 then
cls()
print("dead", 37, 70, 14)
end
end
And when I try to run the program an error message appear which says :
'then' expected near ','
I've searched a lot but never found an answer. Can somebody help?
You're trying to use an
if
formatted:You can assign values to multiple variables with syntax a little like what you've used here. For example,
p.x, p.y = 64,45
would setp.x
to64
andp.y
to45
. But you can't check for equality on multiple variables in that way. You need to check each variable separately:Your code tries to use
p.x, p.y == 64, 45
as a condition for yourif
branch. This doesn't work because lua doesn't understand this to meanp.x == 64 and p.y == 45
. Instead it understands it as a list of unrelated statements (p.x
,p.y == 64
, and45
), and trips up on the comma betweenp.x
andp.y
.