title: Function returning null in Godot GDscript
body: <p>I'm currently developing a inventory system and I'm trying to make a check if the item can go on the inventory or hotbar before the player can pick it using Booleans. the only problem is the function that checks if the item can stack or take a slot always returns null. Would appreciate any insight on this!</p>
  <p>the item script:</p>
  <pre><code>extends KinematicBody2D
  
  const ACCELERATION = 600
  const MAX_SPEED = 600
  var velocity = Vector2.ZERO
  var itemName
  var itemQuantity = 1
  var player = null
  var beingPickedUp = false
  var distanceToDestroyItem = 10
  var destroyItemCounter = true
  
  func initialize(name, quantity):
      itemName = String(name)
      itemQuantity = quantity
      $Sprite.texture = load(&quot;res://Inventory/Items/ItemIcons/&quot; + itemName + &quot;.png&quot;)
  
  func _physics_process(delta):
      if beingPickedUp == false:
              velocity = velocity.move_toward(Vector2.ZERO, ACCELERATION * delta)
      else:
          var distance = global_position.distance_to(player.global_position)
          destroyItemCounter = PlayerInventory.checkToAddItem(itemName, itemQuantity)
          if destroyItemCounter == true:
              var direction = global_position.direction_to(player.global_position)
              velocity = velocity.move_toward(direction * MAX_SPEED, ACCELERATION * delta)
              velocity = move_and_slide(velocity, Vector2.UP)
              distance = global_position.distance_to(player.global_position)
              if distance &lt; distanceToDestroyItem:
                  PlayerInventory.addItem(itemName, itemQuantity)
                  queue_free()
          else:
              beingPickedUp = false
      velocity = move_and_slide(velocity, Vector2.UP)
  
  func ItemPickUp(body):
      player = body
      beingPickedUp = true
  </code></pre>
  <p>the function it calls:</p>
  <pre><code>func checkToAddItem(itemName, itemQuantity, slotType = inventory): 
      for item in slotType:
          if slotType[item][0] == itemName:
              var stackSize = int(JsonData.itemData[itemName][&quot;StackSize&quot;])
              var ableToStack = stackSize - slotType[item][1]
              if ableToStack &gt;= itemQuantity:
                  return true
              else:
                  itemQuantity = itemQuantity - ableToStack
      if slotType == inventory:
          for i in range(INVENTORY_SLOTS):
              if inventory.has(i) == false:
                  return true
              if i == INVENTORY_SLOTS - 1:
                  checkToAddItem(itemName, itemQuantity, hotbar)
      else:
          for o in range(HOTBAR_SLOTS):
              if hotbar.has(o) == false:
                  return true
              if o == HOTBAR_SLOTS - 1:
                  return false
  </code></pre>