My old thread about my apple game was starting to feel cluttered, so I’ve made a new one. I’m almost finished, but there’s just one problem. I want a sound effect to play just once when the bucket (player sprite) hits the ground. The code below causes the sound effect to play over and over as long as the bucket is at y=85 (the ground). I think the solution might have to do with making a new boolean or state, but I could use some guidance.
--enter hover
if btnp(❎) and hover<=0 then
hover = hover_max
y=75
--stay hovered, count down
elseif btn(❎) and (hover >0) then
hover-=1
y=75
--land
else
hover=0
y=85
sfx(05)
end
I’m also trying this instead (play the sound when the bucket is just an imperceptibly tiny bit above ground and looks like it has landed), but keep getting syntax errors.
Yeah you’ll want a boolean check to see if it’s been played, and then reset it when the bucket leaves the ground again. Probably give yourself a bit of a margin so if the bucket twitches 1px for some reason it doesnt just trigger the sound over and over.
Thought so. Still learning the syntax, so can you show me how that might look with my existing code? I have put sound_played=false in init, and added this code:
if hover-=1 and y=85 then
sfx(05)
sound_played=true
end
but I’m getting a syntax error and I think I’m missing something too.
I don’t use PICO-8, but you seem to be telling it to set the variable to false if it’s NOT set to false. If the code is running on a loop, when it runs again, it’ll return false and play the sound again.
You could just make it so that it does nothing if sound_played is not false. Then you could change it back to false at some other point. If this is a “game over” scenario, you could just set the variable to false when the player restarts.
I’m super sick right now so I don’t know if this makes sense haha.
In that case, I’d probably just set that particular code to do nothing if the variable is not false. Then, I’d have some other place on the code where I’d change the variable back to false once the bucket is placed somewhere else.
Edit: oops, sorry, that’s unhelpful. Maybe set it to false within the “enter hover state” section?
I tried to do the same thing for another sound effect at game over, with outro_played = false in init. Still getting the continuous droning. What have I done wrong?
if gameover==true then
outro_played= false
print ("time's up! \npress ❎ to restart \nscore: "..score,26,30,7)
if outro_played==false then
outro_played=true
sfx(06)
end
Congratulations on making your game! Programming is not easy and you should be proud of yourself for doing this. Learning in public like this is very intimidating but I think it’s also very rewarding, and this thread is a great example of it going well.
Adding to this thread yet again because I have a request for someone experienced in pico-8.
I am trying so hard to learn collision, but none of the online tutorials break it down into tiny enough pieces for my squidgy brain to retain much of anything.
I’ve started a new practice game. So far, I have my player (px, py) moving around in 4 directions. And I have some map tiles marked with flag 0. Now I need to turn those flag 0 tiles into walls that my player can’t pass through.
So my request is this: Show me how to do that, in bite sized steps, one reply at a time. Like, smaller steps than you think they need to be. Walk me through the first little line or two of code, before even showing me the second step. Then, when I’m done with the first step (like… using mget to see what tile I’m on, or whatever comes first), I’ll let you know it’s time for the second bit.
Does that make sense? It might be the only way I can learn to make stuff hit walls, without my brain hitting a wall.