title: Integer is not being updated
body: <p>I am making a game that includes a high score label that comes up once the player dies, along with a restart button. Overall the high score, which is an integer, works fine but there is one problem. If you reach a new high score in that round you just finished you have to die again for it to show the new high score. Lets say I play the game while the high score is already 15 and I score 17 when the high score label comes up it still shows 15. After I restart the game and the high score comes up again it will now show 17. The high score is not updating when I want it to.</p>
  
  <pre><code>import SpriteKit
  
  struct physicsCatagory {
      static let person : UInt32 = 0x1 &lt;&lt; 1
      static let Ice : UInt32 = 0x1 &lt;&lt; 2
      static let IceTwo : UInt32 = 0x1 &lt;&lt; 3
      static let IceThree : UInt32 = 0x1 &lt;&lt; 4
      static let Score : UInt32 = 0x1 &lt;&lt; 5
  }
  
  class GameScene: SKScene, SKPhysicsContactDelegate {
  
      var Highscore = Int()
      var timeOfLastSpawn: CFTimeInterval = 0.0
      var timePerSpawn: CFTimeInterval = 1.2
      var scorenumber = Int()
      var lifenumber = Int()
      var SpeedNumber : Double = 0.5
      var person = SKSpriteNode(imageNamed: "Person1")
      let Score = SKSpriteNode()
      var ScoreLable = SKLabelNode()
      var Highscorelabel = SKLabelNode()
      let BackGround = SKSpriteNode (imageNamed: "BackGround")
      var restartButton = SKSpriteNode()
      var Died = Bool()
  
      func restartScene(){
          self.removeAllChildren()
          self.removeAllActions()
          scorenumber = 0
          lifenumber = 0
          createScene()
          random()
          //spawnThirdIce()
          Died = false
          timeOfLastSpawn = 0.0
          timePerSpawn = 1.2
      }
  
      func createScene(){
          physicsWorld.contactDelegate = self
  
          if (scorenumber &gt; Highscore){
              var Highscoredefault = NSUserDefaults.standardUserDefaults()
              Highscoredefault.setValue(scorenumber, forKey: "HighScore")
          }
  
          var Highscoredefault = NSUserDefaults.standardUserDefaults()
          if (Highscoredefault.valueForKey("HighScore") != nil){
              Highscore = Highscoredefault.valueForKey("HighScore") as! NSInteger
          }
          else{
              Highscore = 0
          }
  
          lifenumber = 0
          SpeedNumber = 1
  
          BackGround.size = CGSize(width: self.frame.width, height: self.frame.height)
          BackGround.position = CGPointMake(self.size.width / 2, self.size.height / 2)
          BackGround.zPosition = -5
          self.addChild(BackGround)
  
          Score.size = CGSize(width: 2563, height: 1)
          Score.position = CGPoint(x: 320, y: -20)
          Score.physicsBody = SKPhysicsBody(rectangleOfSize: Score.size)
          Score.physicsBody?.affectedByGravity = false
          Score.physicsBody?.dynamic = false
          Score.physicsBody?.categoryBitMask = physicsCatagory.Score
          Score.physicsBody?.collisionBitMask = 0
          Score.physicsBody?.contactTestBitMask = physicsCatagory.IceThree
          Score.color = SKColor.blueColor()
          Score.zPosition = -5
          self.addChild(Score)
  
          person.zPosition = 1
          person.position = CGPointMake(self.size.width/2, self.size.height/9.5)
          person.setScale(0.6)
          person.physicsBody = SKPhysicsBody (rectangleOfSize: CGSize(width: 1000, height: 50))
          person.physicsBody?.affectedByGravity = false
          person.physicsBody?.categoryBitMask = physicsCatagory.person
          person.physicsBody?.contactTestBitMask = physicsCatagory.Ice
          person.physicsBody?.collisionBitMask = physicsCatagory.Ice
          person.physicsBody?.dynamic = false
          person.physicsBody?.affectedByGravity = false
                  self.addChild(person)
  
          ScoreLable = SKLabelNode()
          ScoreLable.fontName = "Arial"
          ScoreLable.position = CGPoint(x: self.frame.width / 2, y: 1700)
          ScoreLable.text = "\(scorenumber)"
          ScoreLable.fontColor = UIColor.yellowColor()
          ScoreLable.fontSize = 150
          self.addChild(ScoreLable)
  
          Highscorelabel.fontName = "Arial"
          Highscorelabel.position = CGPoint(x: self.frame.width / 2, y: 1400)
          Highscorelabel.text = "HighScore: \(Highscore)"
          Highscorelabel.fontSize = 150
          Highscorelabel.fontColor = UIColor.yellowColor()
          Highscorelabel.zPosition = -7
          self.addChild(Highscorelabel)
      }
  
      func random() -&gt; CGFloat{
          return CGFloat(Float(arc4random()) / 0xFFFFFFFF)
      }
  
      func random(min min: CGFloat, max: CGFloat) -&gt; CGFloat{
          return random() * (max - min) + min
      }
  
      var gameArea: CGRect
  
      override init(size: CGSize) {
          let maxAspectRatio: CGFloat = 16.0/9.0
          let playableWidth = size.height / maxAspectRatio
          let margin = (size.width - playableWidth) / 2
          gameArea = CGRect(x: margin, y: 0, width: playableWidth, height: size.height)
  
          super.init(size: size)
      }
  
      required init?(coder aDecoder: NSCoder) {
          fatalError("init(coder:) has not been implemented")
      }
  
      override func didMoveToView(view: SKView) {
          createScene()
      }
  
      func createButton(){
          restartButton = SKSpriteNode(imageNamed: "Restart Button")
          restartButton.position = CGPoint(x: 768, y: 1024)
          restartButton.zPosition = 6
          restartButton.setScale(2.3)
          self.addChild(restartButton)
      }
  
       func didBeginContact(contact: SKPhysicsContact) {
              let firstBody = contact.bodyA
              let secondBody = contact.bodyB
  
          if firstBody.categoryBitMask == physicsCatagory.person &amp;&amp; secondBody.categoryBitMask == physicsCatagory.IceThree || firstBody.categoryBitMask == physicsCatagory.IceThree &amp;&amp; secondBody.categoryBitMask == physicsCatagory.person{
  
             scorenumber++
  
              if scorenumber == 20 {
                timePerSpawn = 1.0
              }
              if scorenumber == 40{
                  timePerSpawn = 0.89
              }
              if scorenumber == 60{
  
                  timePerSpawn = 0.6
              }
              if scorenumber == 80{
                  timePerSpawn = 0.5
              }
              if scorenumber == 100{
                  timePerSpawn = 0.4
              }
              if scorenumber == 120{
                  timePerSpawn = 0.3
              }
  
              ScoreLable.text = "\(scorenumber)"
              CollisionWithPerson(firstBody.node as! SKSpriteNode, Person: secondBody.node as! SKSpriteNode)  
          }
  
          if firstBody.categoryBitMask == physicsCatagory.Score &amp;&amp; secondBody.categoryBitMask == physicsCatagory.IceThree ||
              firstBody.categoryBitMask == physicsCatagory.IceThree &amp;&amp; secondBody.categoryBitMask == physicsCatagory.Score{
                  lifenumber++
  
                  if lifenumber == 1{
                      //person.texture
                      person.texture = SKTexture (imageNamed: "Flower#2")
                  }
                  if lifenumber == 2{
              person.texture = SKTexture (imageNamed: "Flower#3")
          }
                  if lifenumber == 3{
                     // self.addChild(Highscorelabel)
                      Highscorelabel.zPosition = 5
                      createButton()
                      person.zPosition = -6
                      person.texture = SKTexture (imageNamed: "Person1")
                      //person.removeFromParent()
                      Died = true
                  }
          }
      }
  
      func CollisionWithPerson (Ice: SKSpriteNode, Person: SKSpriteNode){
        Person.removeFromParent()
  
         // if (scorenumber &gt; Highscore){
           //   var Highscoredefault = NSUserDefaults.standardUserDefaults()
             // Highscoredefault.setValue(scorenumber, forKey: "HighScore")
  
          //} 
      }
  
      func spawnThirdIce(){
          if Died == true {
          } else
          {
  
          var Ice = SKSpriteNode(imageNamed: "Ice")
          Ice.zPosition = 2
          Ice.setScale(1.5)
          Ice.physicsBody = SKPhysicsBody(rectangleOfSize: Ice.size)
          Ice.physicsBody?.categoryBitMask = physicsCatagory.IceThree
          Ice.physicsBody?.contactTestBitMask = physicsCatagory.person | physicsCatagory.Score
          Ice.physicsBody?.affectedByGravity = false
          Ice.physicsBody?.dynamic = true
  
          let randomXStart = random(min:CGRectGetMinX(gameArea), max: CGRectGetMaxX(gameArea))
          let randomXend = random(min:CGRectGetMinX(gameArea),max: CGRectGetMaxX(gameArea))
  
          let startPoint = CGPoint(x: randomXStart, y: self.size.height * 1.2)
          let endpoint = CGPoint(x: randomXend, y: -self.size.height * 0.2)
          Ice.position = startPoint
          let moveEnemy = SKAction.moveTo(endpoint, duration: 2.0)
          let deleteEnemy = SKAction.removeFromParent()
          let enemySequence = SKAction.sequence([moveEnemy , deleteEnemy])
          Ice.runAction(enemySequence)
  
          self.addChild(Ice)
          }
      }
  
          override func touchesBegan(touches: Set&lt;UITouch&gt;, withEvent event: UIEvent?) {
              for touch in touches{
                  let location = touch.locationInNode(self)
  
                  if Died == true{
                      if restartButton.containsPoint(location){
                          restartScene()
                      }
                  }
              }
      }
  
      override func touchesMoved(touches: Set&lt;UITouch&gt;, withEvent event: UIEvent?) {
          if Died == true {
          }
          else{
          for touch: AnyObject in touches {
              let location = touch.locationInNode(self)
              let previousTouch = touch.previousLocationInNode(self)
              let ammountDragged = location.x - previousTouch.x
  
              person.position.x += ammountDragged
  
              if person.position.x &gt; CGRectGetMaxX(gameArea) - person.size.width/2{
                  person.position.x = CGRectGetMaxX(gameArea) - person.size.width/2
              }
  
                  if person.position.x &lt;  CGRectGetMinX(gameArea) + person.size.width/2{
                      person.position.x = CGRectGetMinX(gameArea) + person.size.width/2
  
              }
              }
          }
      }
  
      override func update(currentTime: CFTimeInterval) {
          /* Called before each frame is rendered */
          if (currentTime - timeOfLastSpawn &gt; timePerSpawn) {
              spawnThirdIce()
              self.timeOfLastSpawn = currentTime
          }
      }
  }
  </code></pre>
  
  <p>Ok this is what I added to if life number = 3:</p>
  
  <pre><code>if lifenumber == 3{
  
                                   if (scorenumber &gt; Highscore){
              var Highscoredefault = NSUserDefaults.standardUserDefaults()
              Highscoredefault.setValue(scorenumber, forKey: "HighScore")
  
          }
  
  
          var Highscoredefault = NSUserDefaults.standardUserDefaults()
          if (Highscoredefault.valueForKey("HighScore") != nil){
  
              Highscore = Highscoredefault.valueForKey("HighScore") as! NSInteger
          }
          else{
              Highscore = 0
  
          }
                      self.addChild(Highscorelabel)
                      createButton()
                      person.zPosition = -6
                      person.texture = SKTexture (imageNamed: "Person1")
                      Died = true
                  }
  </code></pre>