1

我环顾四周,我已经收集到这意味着中断是无法到达的,但我不明白它是如何无法到达的,或者它试图达到什么。我得到错误的代码如下,也许有人可以告诉我要添加什么以使中断可达:

#region :buy <item>

case "buy":
    string Item = stringManager.wrapParameters(args, 1);

    if (Item == "bread") 
    {
        int foodfunds;
        int myfood;
        int foodCheck;
        int creditCheck;
        using (DatabaseClient dbClient = Eucalypt.dbManager.GetClient())
            foodfunds = dbClient.getInt("SELECT credits FROM users WHERE name = '" + _Username + "'");
        using (DatabaseClient dbClient = Eucalypt.dbManager.GetClient())
            myfood = dbClient.getInt("SELECT food FROM users WHERE name = '" + _Username + "'");
        if (foodfunds < 10)
        {
            Room.sendData("BK" + "Not enough cash.");
        }
        if (_roomID != 193)
        {
            sendData("BK" + "You must be in the supermarket to buy bread");
        }
        else
        {
            using (DatabaseClient dbClient = Eucalypt.dbManager.GetClient())
                dbClient.runQuery("UPDATE users SET food = food + 1 WHERE name = '" + _Username + "'");
            using (DatabaseClient dbClient = Eucalypt.dbManager.GetClient())
                foodCheck = dbClient.getInt("SELECT food FROM users WHERE name = '" + _Username + "'");
            using (DatabaseClient dbClient = Eucalypt.dbManager.GetClient())
                dbClient.runQuery("UPDATE users SET credits = credits - 10 WHERE name = '" + _Username + "'");
            using (DatabaseClient dbClient = Eucalypt.dbManager.GetClient())
                creditCheck = dbClient.getInt("SELECT credits FROM users WHERE name = '" + _Username + "'");
            Room.sendShout(roomUser, "*Buys a loaf of bread and stashes in bag*");
            Room.sendSaying(roomUser, "(Now have: " + foodCheck + " loaves of bread)");
            Room.sendSaying(roomUser, "(Now have: " + creditCheck + " credits left)");
        }
        if (myfood > 255)
        {
            Room.sendData("BK" + "You cannot carry anymore food!");
        }
        break;
    }
#endregion
4

2 回答 2

6

该错误意味着在某些情况下break;不会被击中。

具体来说,if (Item == "bread")是不对的。

于 2013-02-25T03:42:57.150 回答
1

最后移到break外面}。使用您的代码,如果 Item 不是“面包”,break则无法到达。

于 2013-02-25T03:44:08.707 回答