小编J. *_*Doe的帖子

C++ Switch()Bug

我一直在开发一个使用该switch()功能的项目,如下所示:

switch (selectedMenu) {
    case 1:
        switch (selectedIndex) {
            case 0:
                invisibility = !invisibility;
                break;
            case 1:
                invincibility = !invincibility;
                break;
            case 2:
                superjump = !superjump;
                break;
            case 3:
                //Option 4
                break;
            case 4:
                //Option 5
                break;
        }
    case 2:
        switch (selectedIndex) {
            case 0:
                //Option 2
                break;
            case 1:
                //Option 2
                break;
            case 2:
                //Option 3
                break;
            case 3:
                //Option 4
                break;
            case 4:
                //Option 5
                break;
        }
    case 3:
        switch (selectedIndex) {
            case 0:
                //Option 2 …
Run Code Online (Sandbox Code Playgroud)

c++ switch-statement

1
推荐指数
1
解决办法
73
查看次数

带有3个参数的Sprintf不起作用

我正在进行游戏修改,但由于sprintf使用可能不正确,我的代码的一小部分似乎会导致游戏崩溃.

Menu& Menu::scroller(char** textArray, int* index, int numItems, bool fast) {
    char buffer[60];
    numItems--;

    if (hovered()) {
        lrInstruction = true;
        fastScrolling = fast;
        if (rightPress || (rightHold && fast)) {
            playSound("NAV_UP_DOWN");
            if (*index >= numItems) {
                *index = 0;
            }
            else {
                *index = *index + 1;
            }
        }
        else if (leftPress || (leftHold && fast)) {
            playSound("NAV_UP_DOWN");
            if (*index <= 0) {
                *index = numItems;
            }
            else {
                *index = *index - 1;
            }
        }
    }

    if (hovered()) { …
Run Code Online (Sandbox Code Playgroud)

c++ printf

-4
推荐指数
1
解决办法
247
查看次数

标签 统计

c++ ×2

printf ×1

switch-statement ×1