In my code ,when the user completes a level, it unlocks the next level (out of a total of 15 levels).
However, I have noticed that, when I complete the level, first time, it works, however, when I go back to it and try again, it crashes with this error;
[__NSCFArray replaceObjectAtIndex:withObject:]: mutating method sent to immutable object
The code part is this;
//Unlock Next Level
if (levelNumber != 15) {
[m_appDelegate.levels replaceObjectAtIndex:levelNumber withObject:[NSNumber numberWithBool:NO]];
[m_appDelegate saveLevels];
}
If I remove this line;
[m_appDelegate.levels replaceObjectAtIndex:levelNumber withObject:[NSNumber numberWithBool:NO]];
Then the app does not crash, but of course, it does not unlock any further levels.
Some references below that may help;
int levelNumber;
@property (nonatomic, readwrite) int levelNumber;
- (void) actionLockedLevel:(id)sender {
selectedLevel = ((CCNode*)sender).tag;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Level Locked" message:@"Level is locked. Pass the previous level first." delegate:nil cancelButtonTitle:@"No" otherButtonTitles:nil];
[alert show];
}
- (void) actionUnlockedLevel:(id)sender {
CCScene *scene = [CCScene node];
TimedLevel *layer = [TimedLevel node];
layer.levelNumber = ((CCNode*)sender).tag;
[scene addChild:layer];
[[CCDirector sharedDirector] replaceScene:scene];
}
Aucun commentaire:
Enregistrer un commentaire