heres the code I need help with.
if (itemAmount >= usedWithAmount) {
for (int i = 0; i < 10; i++) {
if (amountToTransfer == 6) {
usedWithAmount = i;
break;
}
amountToTransfer = itemAmount - i;
System.out.println(amountToTransfer);
}
} else if (itemAmount < usedWithAmount) {
for (int i = 0; i < 10; i++) {
if (amountToTransfer == 6) {
itemAmount = i;
break;
}
amountToTransfer = usedWithAmount - i;
}
}
Alright, people couldn't understand the first time, so I'll go more in depth.
This is used for in my game you have potions. The potions have an amount in them. A potion with (6) at the end, has 6 doses left, (5) has 5 doses left, etcetc.
I'm making it so when you use a potion on another one, it transfers the doses from the potion to the other potion to make it full.
So lets say I have a potion with 5 doses left(represented as itemAmount), and I use it on another potion which has 2 doses left(represented as usedWithAmount).
What I want the algorithm above to do, is use the value of the first potion(itemAmount), and find out how many doses it should transfer to the other potion to make it full(6 doses = full).
So if I used the 5 dose potion with the 2 dose potion, the 5 dose potion should lose 4 doses, while the 2 dose potion gets 4 doses, I want the amountToTransfer(in this case is 4) to represent how many doses to remove from the first item, and to be added to the second item.
usedWithAmount + amountToTransfer = 6?amountToTransfer = Math.min(itemAmount, 6 - usedWithAmount);