我在 iPhone 上使用 cocos2d,我设置了一个单例来存储玩家的所有数据和变量,我需要知道这是否可行,所以在伪代码中它会是这样的:
players * playersDataManager = [players playersSaveDataManager];
selected = "sword"
name = (@"%@AttRange",selected);
AttRange = playersDataManager.name;
会根据选择的玩家而name
改变,因此 `AttRange 也会改变。我只是不知道如何在实际代码中设置它。这是我正在使用的实际代码:
-(void)showAttackRange:(NSMutableString *)selected {
players * playersDataManager = [players playersSaveDataManager];
NSMutableString * name1 = [NSMutableString stringWithString:@"MaxRange"];
[name1 insertString:selected atIndex:0];
int r = [playersDataManager valueForKey:name1];
NSLog(@"%@%i",name1,r);
}