Godot Version
4.3
Question
I am trying to check when my inventory system has all slots full and when the inventory is maxed out. I have my inventory grid (parent to inventory slots) check each slot that has a bool for if a slot has an item(stackTaken) as well as a bool if a slots stack is full(stackFull).
In the inventory grid script I have a func to check each child slot if they are taken as well as if a slot is max count. This is where I keep confusing myself.
func checkInventoryFull():
for items in self.get_children():
#If all stacks are not full
if !items.stackFull:
inventory_max = false
else:
#If all stacks are full
inventory_max = true
if !items.stackTaken:
inventory_full = false
else:
inventory_full = true
I am having issues trying to figure out the best way to check when all children of the inventory grid have the stackTaken bool = true and the same for stackFull. It will not update if an item is removed, once either the inventory max or full bool is true; it will not reset to false.
Idk if im explaining it right hopefully these screenshots help explain the issue im having.
1 - read the gdscript style guide and follow it.
2 - for instance, the name of a function should be in snake_case
.
these things will make code easier to read.
3 - use not
instead of !
4 - you can assign the result of an expression instead of this birds nest. example:
inventory_max = items.stackFull
inventory_full = items.stackTaken
this is the same as all the code you posted:
func check_inventory_full():
for items in get_children():
inventory_max = items.stack_full
inventory_full = items.stack_taken
5 - it doesn’t seem to do anything.
what is inventory_max and inventory_full? you are overriding the value in every step of the for loop.
6 - you should be using numbers. count the max number of items that can exist and do a count instead of this true/false thing. then check the number with the max number.
var stacks_full : int = 0
var stacks_taken : int = 0
for i in get_children():
if i.stack_full:
stacks_full += 1
if i.stack_taken:
stacks_taken += 1
if stacks_full == stacks_max:
#INVENTORY FULL
2 Likes
thank you for help! inventory_max and inventory_full are both bools that i was trying to use as a way to check if the player can add an item to inventory. since there are some items that stack and some that don’t i have been struggling to fill a items stack when the all inventory slots are taken but the stack is not full yet.