1. TetrisKid48

    OP TetrisKid48 Newbie
    Newcomer

    Joined:
    Dec 3, 2019
    Messages:
    9
    Country:
    United States
    Hey, I was working on a homebrew project (text-based game) and had a problem. When I run the program, it immediately runs through all the code and if statements to check if buttons are pressed, therefore outputting the first text then ending and crashing instantly. How would I wait for the A or B button to be pressed to continue?
    Code:
    #include <3ds.h>
    #include <stdio.h>
    #include <iostream>
    using namespace std;
    
    int main (int argc, char **argv)
    {
        hidInit();
        hidScanInput();
        gfxInitDefault();
        consoleInit(GFX_TOP, NULL);
        u32 kDown = hidKeysDown();
        cout << "Does this code work? \n";
        cout << "Press A for yes and B for no. ";
    //i need to pause and wait for an input here
        if (kDown & KEY_A)
        {
             goto label2;
        }
        if (kDown & KEY_B)
        {
             goto labelinc;
        }
    
    Thanks for any help!
     
    RyuShinobi500 likes this.
  2. RyuShinobi500

    RyuShinobi500 C0D3 N1Nj4
    Member

    Joined:
    Oct 25, 2019
    Messages:
    484
    Country:
    United States
    Try this

    Code:
    #include <3ds.h>
    #include <stdio.h>
    #include <iostream>
    using namespace std;
    
    int main (int argc, char **argv)
    {
        gfxInitDefault();
        consoleInit(GFX_TOP, NULL);
       
        cout << "Does this code work? \n";
        cout << "Press A for yes and B for no. ";
    
        while (aptMainLoop())
        {
            gspWaitForVBlank();
            gfxSwapBuffers();
            hidScanInput();
    
            u32 kDown = hidKeysDown();
           
            if (kDown & KEY_START)
            {
                break;
            }
           
            if (kDown & KEY_A)
            {
                goto label2;
            }
           
            if (kDown & KEY_B)
            {
                goto labelinc;
            }
           
        }
       
        gfxExit();
        return 0;
    }
    This should solve your problem
     
    TetrisKid48 and Extrasklep like this.
  3. Extrasklep

    Extrasklep gbaTemp Fan
    Member

    Joined:
    Aug 24, 2017
    Messages:
    736
    Country:
    Poland
    Put it in a loop
    You should also avoid using goto
     
    RyuShinobi500 likes this.
  4. TetrisKid48

    OP TetrisKid48 Newbie
    Newcomer

    Joined:
    Dec 3, 2019
    Messages:
    9
    Country:
    United States
    Thanks guys! I'll tell you if it works!
     
    Extrasklep likes this.
  5. RyuShinobi500

    RyuShinobi500 C0D3 N1Nj4
    Member

    Joined:
    Oct 25, 2019
    Messages:
    484
    Country:
    United States
    Glad to be of help
     
    Extrasklep and TetrisKid48 like this.
  6. TetrisKid48

    OP TetrisKid48 Newbie
    Newcomer

    Joined:
    Dec 3, 2019
    Messages:
    9
    Country:
    United States
    Thanks! It works! :yay3ds:there were a few problems, but I got them worked out. Mostly just typing things wrong lol
     
  7. RyuShinobi500

    RyuShinobi500 C0D3 N1Nj4
    Member

    Joined:
    Oct 25, 2019
    Messages:
    484
    Country:
    United States
    Okay sorry for the typos my computer cannot compile code anymore
     
Draft saved Draft deleted
Loading...

Hide similar threads Similar threads with keywords - coding,