我希望做類似簡單整潔的方法來調用多個變量
int ItemNames;
typedef enum ItemNames {apple, club, vial} ItemNames;
+(BOOL)GetInventoryItems{return ItemNames;}
apple=1; //Compiler Error.
的問題是,是,我不能在枚舉設置一個變量爲一個新值。編譯器告訴我,我在枚舉中「重新聲明瞭」一個整數。此外,它不會正確返回值。 因此,我不得不爲每個項目使用if語句來檢查它是否存在。
+ (void)GetInventoryItems
{
if (apple <= 1){NSLog(@"Player has apple");}
if (club <= 1){ NSLog(@"Player has club");}
if (vial <= 1){NSLog(@"Player has vial");}
if (apple == 0 && club == 0 && vial == 0){NSLog(@"Player's Inventory is Empty.");}
}
是否有解決方法?
謝謝!我不確定房間是什麼(編譯器也沒有),但struct正是我所期待的! – evdude100 2011-05-18 15:27:04
我不知道你在創建庫存,所以我說這是一個房間;它只是一個變量名稱。 – 2011-05-18 15:30:01
當我嘗試room.apple = 1;它給了我錯誤。 – evdude100 2011-05-18 15:34:37