title: How to make statement work only for the selected level in Sprite Kit
body: <p>So Here I have this code </p>
  
  <pre><code> if collision == PhysicsCategory.Cat | PhysicsCategory.Bed {
              print("SUCCESS")
              win()
              if currentLevel &lt; 10 {
                  currentLevel += 1
              }
  </code></pre>
  
  <p>And basically this statement works for every single level that I have .
  I want to make it like this for only one level</p>
  
  <pre><code> if collision == PhysicsCategory.Cat | PhysicsCategory.Bed| PhysicsCategory.Bottle {
              print("SUCCESS")
              win()
              if currentLevel &lt; 10 {
                  currentLevel += 1
              }
  </code></pre>
  
  <p>But If I will use it it will mean that the collision with bottle will be needed in every single level , however I want to use it only in one level</p>
  
  <p>I am using swift</p>
  
  <p>thank you!</p>
  
  <p>FOR @Mundi </p>
  
  <p>Here is code in GameScene</p>
  
  <pre><code> import SpriteKit
  Game scene
  protocol EventListenerNode {
      func didMoveToScene()
  }
  protocol InteractiveNode {
      func interact()
  }
  
  struct PhysicsCategory {
      static let None:  UInt32 = 0
      static let Cat:   UInt32 = 0b1 // 1
      static let Block: UInt32 = 0b10 // 2
      static let Bed:   UInt32 = 0b100 // 4
      static let Edge:  UInt32 = 0b1000 // 8
      static let Label: UInt32 = 0b10000 // 16
      static let Spring:UInt32 = 0b100000 //32
      static let Hook: UInt32 = 0b1000000 //64
      static let Bottle: UInt32 = 0b10000000 //64
  
  }
  
  class GameScene: SKScene, SKPhysicsContactDelegate {
  
      var bedNode: BedNode!
      var catNode: CatNode!
      var lineNode: LineNode!
      var bottleNode: BottleNode!
      var desiredCollision = PhysicsCategory.Cat | PhysicsCategory.Bed
  
  
      var playable = true
  
      override func didMove(to view: SKView) {
          // Calculate playable margin
          let maxAspectRatio: CGFloat = 16.0/9.0
          let maxAspectRatioHeight = size.width / maxAspectRatio
          let playableMargin: CGFloat = (size.height - maxAspectRatioHeight)/2
          let playableRect = CGRect(x: 0, y: playableMargin,
                                    width: size.width, height: size.height-playableMargin*2)
          physicsBody = SKPhysicsBody(edgeLoopFrom: playableRect)
          physicsWorld.contactDelegate = self
          physicsBody!.categoryBitMask = PhysicsCategory.Edge
  
          enumerateChildNodes(withName: "//*", using: { node, _ in
              if let eventListenerNode = node as? EventListenerNode {
                  eventListenerNode.didMoveToScene()
  
  
              }
  
          })
  
          bedNode = childNode(withName: "bed") as! BedNode
          catNode = childNode(withName: "//cat_body") as! CatNode
          bottleNode = childNode(withName: "bottle") as! BottleNode
  
  
  
  
     func didBegin(_ contact: SKPhysicsContact) {
          let collision = contact.bodyA.categoryBitMask | contact.bodyB.categoryBitMask
  
          if collision == PhysicsCategory.Label | PhysicsCategory.Edge {
  
              let labelNode = contact.bodyA.categoryBitMask == PhysicsCategory.Label ?
                  contact.bodyA.node :
                  contact.bodyB.node
  
              if let message = labelNode as? MessageNode {
                  message.didBounce()
              }
          }
  
          if !playable {
              return
          }
  
  
          if currentLevel == 20 { // or whatever level you want
              desiredCollision |= PhysicsCategory.Bottle
  
          }
  
          if collision == desiredCollision {
              print ("Win")
              win()
  
  
          } else if collision == PhysicsCategory.Cat | PhysicsCategory.Edge {
              print("FAIL")
              lose()
  </code></pre>
  
  <p>and here is the code from my BottleBode</p>
  
  <p>import SpriteKit</p>
  
  <pre><code>class BottleNode: SKSpriteNode, EventListenerNode {
      func didMoveToScene() {
          print("bottle added to scene")
  
          let bedBodySize = CGSize(width: 40.0, height: 30.0)
          physicsBody = SKPhysicsBody(rectangleOf: bedBodySize)
          physicsBody!.isDynamic = true
  
          physicsBody!.categoryBitMask = PhysicsCategory.Bottle
          physicsBody!.collisionBitMask = PhysicsCategory.Block | PhysicsCategory.Edge | PhysicsCategory.Spring | PhysicsCategory.Spring
          parent!.physicsBody!.contactTestBitMask = PhysicsCategory.Bed | PhysicsCategory.Edge
  
      }
  }
  </code></pre>
  
  <p>I did as you told me however it still doesn't work, and when the CatNode touches the ground I have lose condition and I am receiving an error.</p>
  
  <p>Here is a picture of how it doesn't work
  <a href="https://i.stack.imgur.com/0JrMJ.png" rel="nofollow noreferrer">https://i.stack.imgur.com/0JrMJ.png</a></p>
  
  <p>and here is an error.</p>
  
  <p><a href="https://i.stack.imgur.com/8VGRd.png" rel="nofollow noreferrer">https://i.stack.imgur.com/8VGRd.png</a></p>
  
  <p>Could you please tell me what wrong ?</p>
  
  <p>Thank you so much </p>