I've followed the "Pico-8: Noob to Pro" course. I've nearly recreated all of the code (with a few tweaks) and decided to add an attack to the main character. I've tried that by adding this melee trick from the course, but can't get it to animate more than one frame, and it also only seems to register when I'm moving. Below is my code. See attached screenshot for readability.
function animate_plr()
--handle animation state
if plr.state=="dead" then
plr.sp=8
--idle
elseif plr.state=="idle" then
plr.sp=1
--attack
elseif btnp(🅾️) then
plr.sp=4
--walk
elseif plr.state=="walk" then
if plr.sp<2.75 then
plr.sp+=0.25
else
plr.sp=1
end
--jump
elseif plr.state=="jump" then
plr.sp=2
end
end
I couldn't follow the melee trick entirely, because I haven't figured out how to embed the logic from it into above elseif statement. I was thinking to also use an "attack" state, but haven't figured out how to make that work.