title: Extremely Simple Saved High Score
body: <p>The game that I am creating has a highScore integer variable that gets assigned when the player loses. I  am using NSUsersDefaults class to save my high score. Here is my code that I am using:</p>
  
  <pre><code>-(void)saveScore {
      [[NSUserDefaults standardUserDefaults] setInteger:score forKey:@"highScore"];
      [defaults setInteger:score forKey:@"highScore"];
      [defaults synchronize];
      NSLog(@"High Score: %i ", highScore);
  }
  
  
  -(IBAction)buttonReleased:(id)sender {
  
  
  [stopWatchTimer invalidate];
  AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
  
  NSString *label0 = @"Hold to Start";
  [labelText setText:label0];
  
  if (score &gt; 0) {
      score--;
  }
  
  else {
      score = 0;
      NSLog(@"Changed score to 0");
  }
  
  
  
  
  if (score &gt; highScore) {
  
  
      [self saveScore];
  
      NSString *scoreMessage =[[NSString alloc] initWithFormat:@"Congrats! You have a new High Score! Click Share High Score to share your score of: %i",score];
  
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"High Score!" message:(NSString *)scoreMessage delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
  
  
  
  
      [alert show];
      [alert release];
  
      score = 0;
  }
  
  else {
  
  
      NSString *scoreMessage =[[NSString alloc] initWithFormat:@"Game Over! Your score was: %i",score];
  
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"GAME OVER!" message:(NSString *)scoreMessage delegate:nil cancelButtonTitle:@"Try Again" otherButtonTitles: nil];
  
      [alert show];
      [alert release];
  
      score = 0;
  }
  
  
  - (void)viewDidLoad
  {
  
  
      [super viewDidLoad];
  
      int highscore = [[NSUserDefaults standardUserDefaults] integerForKey: @"highScore"];
  
      [stopWatchTimer invalidate];
      stopWatchTimer=nil;
  
  
  
  
  }
  </code></pre>
  
  <p>I have been wrestling with this for HOURS! What am I doing wrong?! Note: Can you explain it as simply as possible.</p>
  
  <p>Thanks!
  -Matt</p>