Topic was automatically imported from the old Question2Answer platform.
Asked By
SebSharper
I am trying to implement a system to split the items in my inventory to another slot. For example, let’s say that I have a stacked slot in which one I have 6 items, when splitting, I should have 3 on the initial slot, and 3 in a second slot.
The problem I’m facing is when the number is not an even number. If I split a slot that has 5 items, the initial one should have 3 items, and the second one 2.
How could I get the corresponding values for this?
So, you’re just trying to calculate the number of items to place into 2 separate columns based on the total number of items? And, with an even number of items, each column should have the same number of items and with an odd number of items, the left-hand column should have 1 more?
If so, something like this should work:
func _ready():
var total_items = 11
var left = ceil(float(total_items) / 2)
var right = total_items - left
print(left)
print(right)