Hello
I'm a beginner with PICO-8
I've made my first program : Print a text and wait a key.
Printing text is ok, but not pressing a key.
I don't undertand what is wrong (its my first day with pico-8)
local timer = 0 local show_continue = false local text = { "Year 2183.", "A mysterious signal draws you", "to Thalassa,a forgotten planet", "", "Your ship crashes, leaving you", "stranded in a hostile world", "where technology and nature", "clash.", "", "Recover your gear and survive." } local displayed_text = {} local char_timer = 0 local char_speed = 2 -- Temps entre chaque lettre (plus bas = plus rapide) local line_index = 1 local char_index = 0 function _init() cls() -- Efface l'écran end function _update() if not show_continue then char_timer += 1 if char_timer >= char_speed then char_timer = 0 if line_index <= #text then char_index += 1 if char_index > #text[line_index] then char_index = 0 line_index += 1 end else show_continue = true end end else -- Vérifie si une touche est pressée if btnp(β) or btnp(π ΎοΈ) then cls() print("You pressed a key!", 30, 60) end end end function _draw() cls() -- Efface l'écran avant de dessiner color(8) -- Couleur du texte principal -- Dessine le texte progressif for i = 1, line_index - 1 do print(text[i], 10, 10 + (i - 1) * 10) end -- Dessine la ligne en cours de saisie if line_index <= #text then print(sub(text[line_index], 1, char_index), 10, 10 + (line_index - 1) * 10) end -- Affiche le message "Press a Key to Continue" lorsque terminé if show_continue then color(10) -- Couleur jaune print("press β Key to Continue", 10, 110) end end |
_draw runs every frame after _update and the first thing it does in your code is clear the screen
So, what i should do IS to put my check button code juste After CLS , in _draw ?
Im not so familiar yet with loops...
That should work, or you could use a global boolean that resets to false each frame, set to true in _update if a button is pressed, and operate on that boolean in _draw
[Please log in to post a comment]