Log In  
Log In  

Hi,

I've been dabbling in Pico-8 since yesterday and am loving it so far! However, I have come up against a really frustrating problem and have spent hours trying to figure out why my code doesnt work. I keep getting a
"then" expected near "=" error up, for the line highlighted in the code below. Any ideas of why this isn't working would be very much appreciated!!!

All the best,
Paul.

player = {}
player.x = 5
player.y = 5
player.sprite = 0
player.speed = 2
crab = {}
crab.x = 50
crab.y = 50
crab.sprite = 9
crab.ran = 1

function mover()
player.moving = true
player.sprite += 1
if player.sprite > 4 then
player.sprite = 0
end
end

function movel()
player.moving = true
player.sprite -= 1
if player.sprite <4 then
player.sprite = 8
end
end

function crabmov()
crab.ran = flr(rnd(2))
if crab.ran = 0 then <------------------
crab.x -= 1
end
if crab.ran = 1 then
crab.x += 1
end
end

function _update()
player.moving = false

if btn(0) then
player.x -= player.speed
movel()
end
if btn(1) then
player.x += player.speed
mover()
end
if btn(2) then
player.y -= player.speed
movel()
end
if btn(3) then
player.y += player.speed
mover()
end
if not player.moving then
player.sprite = 0
end

-- decide if the crab moves left or right
crabmov()

end

function _draw()
--cls()
rectfill (0,0,128,128,13)
spr(player.sprite, player.x, player.y)
spr(crab.sprite, crab.x, crab.y)

end

P#26080 2016-07-29 09:05 ( Edited 2016-07-29 15:11)

the highlighted line should use == not =.

== means 'is equal to?', where as '=' is an assignment.

function crabmov()
crab.ran = flr(rnd(2))
if crab.ran == 0 then
crab.x -= 1
end
if crab.ran == 1 then
crab.x += 1
end
end

P#26084 2016-07-29 09:44 ( Edited 2016-07-29 13:46)

Great!

Thank you so much for that Springogeek! Works perfectly now :-)

All the best,

Paul :-)

P#26091 2016-07-29 11:11 ( Edited 2016-07-29 15:11)

[Please log in to post a comment]

About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2019-04-25 22:03 | 0.011s | 2097k | Q:17