Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am going to be setting up IAP for extra lives in my game, but before I do that I wanted to test to see if it would transfer from my purchasing View Controller to my game View Controller and it's not. In my purchasing VC I have

Objective-C
-(void)StartView{
//Life = [[NSUserDefaults standardUserDefaults] integerForKey:@"Life"]; (If in the code then it will not update the LifeCounter.text)
livesUpdated = [NSTimer scheduledTimerWithTimeInterval:0.0001 target:self selector:@selector(LiveUpdatedCheck) userInfo:nil repeats:YES];
}


-(void)LiveUpdatedCheck{
LifeCounter.text = [NSString stringWithFormat:@"%li", (long)Life];
}


-(void)LiveUpdatedCheck{
LifeCounter.text = [NSString stringWithFormat:@"%li", (long)Life];
}


-(IBAction)TenLifePurchase:(id)sender{
    Life = Life + 10;
}


Then in my game VC I have

Objective-C
-(IBAction)StartGame:(id)sender{
Life = [[NSUserDefaults standardUserDefaults] integerForKey:@"Life"];
LifeCounter.text = [NSString stringWithFormat:@"%li", (long)Life];
}


'Life' is declared as an NSInteger in both of my .h files and I used userDefaults just like this to move my high score between 2 view controllers and the same for changing the color of a ball via id integers. How can I fix this problem? Could it be because in-between my purchase controller and my game controller you have to go through a main screen that has no information on 'Life'? Also when you go back to the purchased controller after viewing the game controller it resets back to 0 from whatever number it was, but if you view any other controller then back to purchased then the number will store and not reset back to 0.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900