Hi so I'm quite new to pico-8 so I'm sorry if this is a silly question to ask, but I was wondering if there was a way to wait until something happens. Like the scratch block wait-until. I don't want this to be in an _update() loop as I only want it to happen once, but I also don't want to create too many variables.
My idea was that you were asked a question. You choose and it comes up with a different dialogue depending on your answer.
In the end I want something like this:
if btnp(4) then <----(in an update loop) if qna==false then nexttext() return else nexttext() a=hovertxt qna=false return end end if qna==true then <----- also in update loop if btnp(2) or btn(3) then hovertxt+=1 end if hovertxt>1 then hovertxt==0 end end textdisplay("Hi so, do you think,",function()<----just a custom function that tells the code to run whatever is inside after the dialogue finished. qna=true a=2 <------ in an init loop end) textdisplay("Yes Or No") wait until a==1 or 0 if a==1 textdisplay("you said no!") else textdisplay("you said yes!") end |
if you can help me solve this, it would be very appreciated!



Here's two things to consider:
-
_update and _draw are just variables that are expected to contain references to functions as their values. You can change them as needed.
- While it is usually better to do drawing during the call to _draw (because the timing will be handled by the engine), you are allowed to draw at any time, and you don't need to always clear the full screen when drawing.
For the case in your example, the function to display text could be code to clear the portion of the screen that shows the dialogue/question then prints the new text for the dialogue/question, while the draw and update loops handle just the portion of the screen where the player is given a choice. Then, if you need to go to something completely different, you can just change _update and _draw to be whatever functions the new portion of the game need.
For the more general case of needing a function that waits for a condition, that depends on what the condition is. if you want it to be until the player presses a button, for example, this would work:
function wait_till_x() prev_update = _update _update = function () if (btnp(❎)) then _update = prev_update end end end |
[Please log in to post a comment]