Homebrew Help with C++ coding for 3DS

  • Thread starter Thread starter TetrisKid48
  • Start date Start date
  • Views Views 2,995
  • Replies Replies 6
  • Likes Likes 1

TetrisKid48

Active Member
Newcomer
Joined
Dec 3, 2019
Messages
32
Reaction score
64
Trophies
0
XP
221
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!
 
  • Like
Reactions: Deleted User
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!

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
 
  • Like
Reactions: TetrisKid48 and IC
Thanks! It works! :yay3ds:there were a few problems, but I got them worked out. Mostly just typing things wrong lol
 

Site & Scene News

Popular threads in this forum