gpt4 book ai didi

c++ - "A case label may only be used within a switch"

转载 作者:行者123 更新时间:2023-11-30 03:35:27 26 4
gpt4 key购买 nike

我是编码新手,需要一些帮助。我正在从 GTA Mod 菜单中整理案例,并尝试从 SDK 添加新案例。当我尝试添加它并为其添加一个案例以便它知道该怎么做时,我在标题中得到了错误。我正在用 C++ 编码。

    int activeLineIndexVeh = 0;

void process_veh_menu()
{
const float lineWidth = 230.0;
const int lineCount = 9;

std::string caption = "Vehicle Options";

static struct {
LPCSTR text;
bool *pState;
bool *pUpdated;
} lines[lineCount] = {
{ "Car Spawner", NULL, NULL },
{ "Random Paint", NULL, NULL },
{ "Fix", NULL, NULL },
{ "Custom Plate", NULL, NULL },
{ "Seat Belt", &featureVehSeatbelt, &featureVehSeatbeltUpdated },
{ "Wrap In Spawned", &featureVehWrapInSpawned, NULL },
{ "Invincible", &featureVehInvincible, &featureVehInvincibleUpdated },
{ "Strong Wheels", &featureVehInvincibleWheels, &featureVehInvincibleWheelsUpdated },
{ "Speed Boost", &featureVehSpeedBoost, NULL }
};

DWORD waitTime = 150;
while (true)
{
// timed menu draw, used for pause after active line switch
DWORD maxTickCount = GetTickCount() + waitTime;
do
{
// draw menu
draw_menu_line(caption, lineWidth, 7.9, 14.0, 4.0, 4.0, false, true);
for (int i = 0; i < lineCount; i++)
if (i != activeLineIndexVeh)
draw_menu_line(line_as_str(lines[i].text, lines[i].pState),
lineWidth, 4.0, 60.0 + i * 22.8, 4.0, 9.0, false, false);
draw_menu_line(line_as_str(lines[activeLineIndexVeh].text, lines[activeLineIndexVeh].pState),
lineWidth + 0.0, 2.0, 60.0 + activeLineIndexVeh * 22.9, 4.0, 7.0, true, false);

update_features();
WAIT(0);
} while (GetTickCount() < maxTickCount);
waitTime = 0;

// process buttons
bool bSelect, bBack, bUp, bDown;
get_button_state(&bSelect, &bBack, &bUp, &bDown, NULL, NULL);
if (bSelect)
{
menu_beep();

// common variables
BOOL bPlayerExists = ENTITY::DOES_ENTITY_EXIST(PLAYER::PLAYER_PED_ID());
Player player = PLAYER::PLAYER_ID();
Ped playerPed = PLAYER::PLAYER_PED_ID();

switch (activeLineIndexVeh)
{
case 0:
if (process_carspawn_menu()) return;
break;
case 1:
if (bPlayerExists)
{
if (PED::IS_PED_IN_ANY_VEHICLE(playerPed, 0))
{
Vehicle veh = PED::GET_VEHICLE_PED_IS_USING(playerPed);
VEHICLE::SET_VEHICLE_CUSTOM_PRIMARY_COLOUR(veh, rand() % 255, rand() % 255, rand() % 255);
if (VEHICLE::GET_IS_VEHICLE_PRIMARY_COLOUR_CUSTOM(veh))
VEHICLE::SET_VEHICLE_CUSTOM_SECONDARY_COLOUR(veh, rand() % 255, rand() % 255, rand() % 255);
}
else
{
set_status_text("player isn't in a vehicle");
}
}
break;
case 2:
if (bPlayerExists)
if (PED::IS_PED_IN_ANY_VEHICLE(playerPed, 0))
VEHICLE::SET_VEHICLE_FIXED(PED::GET_VEHICLE_PED_IS_USING(playerPed));
else
set_status_text("player isn't in a vehicle");
break;
// switchable features
default:
if (lines[activeLineIndexVeh].pState)
*lines[activeLineIndexVeh].pState = !(*lines[activeLineIndexVeh].pState);
if (lines[activeLineIndexVeh].pUpdated)
*lines[activeLineIndexVeh].pUpdated = true;
}
waitTime = 200;
}
else
if (bBack || trainer_switch_pressed())
{
menu_beep();
break;
}
else
if (bUp)
{
menu_beep();
if (activeLineIndexVeh == 0)
activeLineIndexVeh = lineCount;
activeLineIndexVeh--;
waitTime = 150;
}
else
if (bDown)
{
menu_beep();
activeLineIndexVeh++;
if (activeLineIndexVeh == lineCount)
activeLineIndexVeh = 0;
waitTime = 150;
}
case 3: // error starts here
Ped playerPed = PLAYER::PLAYER_PED_ID();

// No point in displaying the keyboard if they aren't in a vehicle
if (!PED::IS_PED_IN_ANY_VEHICLE(playerPed, false)) return;

// Invoke keyboard
GAMEPLAY::DISPLAY_ONSCREEN_KEYBOARD(true, "", "", VEHICLE::GET_VEHICLE_NUMBER_PLATE_TEXT(PED::GET_VEHICLE_PED_IS_IN(playerPed, false)), "", "", "", 9);

// Wait for the user to edit
while (GAMEPLAY::UPDATE_ONSCREEN_KEYBOARD() == 0) WAIT(0);

// Make sure they didn't exit without confirming their change, and that they're still in a vehicle
if (!GAMEPLAY::GET_ONSCREEN_KEYBOARD_RESULT() || !PED::IS_PED_IN_ANY_VEHICLE(playerPed, false)) return;

// Update the licenseplate
VEHICLE::SET_VEHICLE_NUMBER_PLATE_TEXT(PED::GET_VEHICLE_PED_IS_IN(playerPed, false), GAMEPLAY::GET_ONSCREEN_KEYBOARD_RESULT());
}
}

最佳答案

这就是它所说的。您有一个 case 标签,它甚至与您的 switch 不在同一条街上!

案例 3: 在从酒吧回来的路上迷路了吗?

关于c++ - "A case label may only be used within a switch",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41300384/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com