Log In  


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


Thank you so much, it worked for me.

It looks like the issue might be with the button codes you're using for detecting key presses. In PICO-8, you should use btnp(4) for the button and btnp(5) for the button. Replace the current button checks with these codes to correctly detect the key presses and continue with the program as expected. I had a tight deadline for a custom essay, and https://academized.com/custom-essay came through for me. The writer assigned to my project was extremely professional and delivered an essay that was not only well-researched but also engaging and insightful. The entire process was seamless, from placing the order to receiving the final product. I’m so impressed with their service and will definitely use them again for future assignments. Highly recommended!



[Please log in to post a comment]