Log In  


Hello again, I am a complete beginner for those who didn't see my previous post. Been trying to create my own functions to perform certain tasks, but having trouble. In this case I was trying to make functions that could draw and move a player, in a way where I could substitute in different players using the brackets at the end of the function. However when I run this I'm just getting a black screen - so I'm guessing something wrong with the draw function? Would appreciate if anyone can point me in the right direction. Thanks in advance for any responses!

my code:

function _init()
--players
jim={
sprite=1,
x=63,
y=63,
w=1,
h=1
}

jon={
sprite=2,
x=63,
y=63,
w=1,
h=1
}

end

function _update()
cls()
move(jim)

end

function _draw()

drawplayer(jim)

end

function move(player)
if btn(➡️) then player.x+=1 end
if btn(⬅️) then player.x-=1 end
if btn(⬆️) then player.y-=1 end
if btn(⬇️) then player.y+=1 end
end

function drawplayer(player)

spr(player.sprite,player.x,player.w,player.h)

end



1

I think what's happening here is that you're missing the y argument in spr() here, which is throwing everything off.

As a suggestion, you might want to remove width and height entirely from your code, unless you know you'll want to be drawing multi-sprite sprites to the screen. It's adding tokens (and complexity) that don't need to be there, and with PICO-8, saving tokens is king. :)


1

Also: I'd recommend moving your cls() call from your _update() function to the _draw() function. cls() is a drawing command, and having it run outside of the _draw() function could cause unintended behavior.


1

Your code looks really good so nice job with that

The bug lies in the drawplayer function. When you call spr(), you are supplying it with the wrong arguments, as well as an awkward number of arguments which is causing the strange error

The way your code is written, spr() only receives the w argument but not the h argument. This seems to cause the whole thing to fizzle out?

Regardless, typing help spr into the console should clear any questions you might have

(BTW, had to delete my last comment. I was mixing things up with a different function.)


2

Thanks so much both!! (can't believe I missed the sprite y 😭)


1

You're welcome! Welcome to the PICO-8 world! 😁


1

A rite of passage



[Please log in to post a comment]