Topic was automatically imported from the old Question2Answer platform.
Asked By
Coenster
Hi
I am not a master at math, so I would like it if some smart person could help me out.
I need to calculate the available space in my inventory and if there is enough space add resources, but if there is not enough space only add some resources until the storage is full. For example: I have 1.7 resources but there is space for only 1.5 in the inventory.
So what I did is:
var overflow = resources - available_space
var able_to _store = resources - overflow
Then i just add the able_ to_ store to the Inventory.
Can someone please show me how to write this simple math more proper? It just feels wrong leaving it like this.
able_to_store = resources - resources - available_space able_to_store = - available_space which is a constant…you’ll always get the same output.
So you could do this: var overflow = available_space - resources
e.g. in a scenario where we have more resources than the inventory can hold:
overflow = 1.5 - 1.7
overflow = - 0.2 so you can need to remove 0.2 resources from the inventory
or in a scenario where we have less resources than capacity:
overflow = 1.5 - 1.0
overflow = + 0.5 …meaning we have the capacity to store 0.5 more resources.
So I guess instead of using overflow, you could use the word capacity to make it more understandable (assuming that I’m using your terms correctly)
Hi, I’m also bad for math, but I like … after thinking and trying several things, the best way I found is this. It can be added and subtracted without exceeding the upper and lower limits.
Sorry but I could not do it using only mathematical formulas.