我希望做类似简单整洁的方法来调用多个变量
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