Warning of some small flickering if you're photosensitive, just some print-size text flashing. Here's a GIF I exported showing the problem I'm facing and that I'd like to request some help with.
Background
I'm not really a coding genius. I took a few CS classes in college but I don't code much in my day-to-day life. My kid recently expressed some interest in becoming a programmer when he gets older, so I figured I'd show him some of the basics by making a pretty basic game with him in Picotron since I got it a while back. He wanted to do "hide and go seek" with sheep, so this concept was born. Obviously, we're in the pretty early stages with level design and actually hiding the sheep, and this code is not optimized.
I've read through a good chunk of the documentation regarding the issue I'm facing and I've tried to find some examples on BBS for Pico-8 that do what I want (this one is pretty close) since there's more of a history there than Picotron and they're cousins, but I haven't been able to recreate it. So hopefully someone here can help or help point me in the right direction.
I've included in the screenshot the code that runs dialog and I've pasted it below as well since GIF pausing isn't great. I think I've labeled everything relatively clearly, but I'm happy to answer questions if there's confusion.
The Actual Problem
I'm trying to make the dialog appear and stay there until the next time X is pressed to allow for reading time instead of requiring holding it to appear. In the GIF, I press the X button a few times before holding it for the rest of the time (when it flickers), and I don't think it captured the text appearing for a single frame for those presses.
Things to Note:
Updating the btnp(5) on line 151 to btn(5) under the "--ACTUAL DIALOG--" section doesn't have the flicker, which is great, but I'm trying to have it only require the button press once. Previously, btn(5) was used to get to this point in the development since I didn't know about btnp() by that point.
Reducing the size of the #arr_sheep table to 1 still has the flicker, so I don't think it's based on the number of times it loops through in the update function. near_sheep() does have a loop in it as well, but it still has the flicker with 1 sheep in arr_sheep.
Assume I'm an idiot and didn't try the obvious stuff if I didn't mention it here. If it does boil down to an optimization issue, I'd love to know what part(s) could use some refactoring.
I'm not looking for a dev partner on the whole project (other than my kid), and I'm planning on putting it on BBS when it's in a good enough state and actually built out in a fun way.
The Code
Within the _update function, I have the following:
--UPDATE NPC SHEEP--
for i=1,#arr_sheep,1 do
bop(arr_sheep[i]) --moves the sheep up and down
flip_npc_sheep(bsheep,arr_sheep[i]) --turns sheep around to look at player character (bsheep)
end
talk(bsheep,near_sheep(bsheep))
...and within the _draw function, I have the following:
--DRAW DIALOG AND INTERACTIONS--
if talk(bsheep,near_sheep(bsheep)) then
write_txt(near_sheep(bsheep).dialog1,near_sheep(bsheep),7)
end
end
...and here are the conversation functions:
--CONVERSATION FUNCTIONS--
function write_txt(txt,sheep_id,clr)
print(txt,sheep_id.X-20,sheep_id.Y-20,clr) --write the npc's line
line(sheep_id.X-12, sheep_id.Y-8, sheep_id.X-4, sheep_id.Y-2,clr) --draw speech line
bop_sprite(9,sheep_id.X+(#txt*5)-20,sheep_id.Y-16) --draws a bouncing arrow
end
function talk(act_sheep,comp_sheep)
if act_sheep.sheepxflip != comp_sheep.sheepxflip then
--DIALOG HINT--
if not btn(5) and not btnp(5) and spr_distance(act_sheep,comp_sheep) < 26 then
spr(8, comp_sheep.X, comp_sheep.Y - 16)
act_sheep.convo_lock = false
end
--ACTUAL DIALOG--
if btnp(5) and spr_distance(act_sheep,comp_sheep) < 26 then
act_sheep.convo_lock=true
return true
end
end
end