Log In  

Hi i try to make my squirrel move to the right it dosen't seem to work but work perfectly with the left any idea ?

player = {}
player.x = 16
player.y = 42
player.sprite = 4
player.speed = 3

function _update()
if btn(0) then
player.x -= player.speed
end
end
if btn(1) then
player.x += player.speed

end
function _draw()
cls()
map(0,0,0,0,16,16)
spr(player.sprite,player.x,player.y,2,2)
end

P#48453 2018-01-22 11:46 ( Edited 2018-01-24 12:51)

player = {}
player.x = 16
player.y = 42
player.sprite = 4
player.speed = 3

function _update()
  if btn(0) then
    player.x -= player.speed
  end
[b][i]end[/i][/b]
if btn(1) then
  player.x += player.speed

end
function _draw()
  cls()
  map(0,0,0,0,16,16)
  spr(player.sprite,player.x,player.y,2,2)
end

That 'end' I've highlighted is your problem. It's closing out the '_update()' function. This makes it so that the 'move right' logic you have right after it is never run.

Move it to after the line that reads 'player.x += player.speed' and it will work the way you're wanting it to.

Note: This is why it helps to indent your code to show what's inside a function or an 'if' statement if you aren't doing that already.

P#48454 2018-01-22 11:54 ( Edited 2018-01-22 16:54)

@enargy
To be fair, their code might actually be indented, but because they didn't put the [code] and [/code] tags around the code, the BBS might have eaten the indentation. But they also might not have indented it. :)

P#48455 2018-01-22 11:59 ( Edited 2018-01-22 17:00)

@Felice yeah that's true, the bbs can strip out formatting unfortunately.

What I meant to say was "if you're not indenting it already"

P#48457 2018-01-22 13:08 ( Edited 2018-01-22 18:08)

Thanks a lot for the help and for the tips i will take the time to make my code cleaner it burn my eyes finally after looking at it again :p

P#48507 2018-01-24 07:51 ( Edited 2018-01-24 12:51)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-04-18 11:10:34 | 0.023s | Q:15