Logic bug on a blueprint for a shop simulator

Hi,
I have a logic bug on this blueprint, busically I don t get the results I should get.
I will describe what it does cause nodes are in my lenguage so probably you wont understand what I wrote.
Basically all start from a trace line by channel(you don t see)(the traceline is because the box shot a ray for refilling the shelf and it need to it the slot) and go to cast to slot(that basically is the shelf slot for products in the store), then I do some check that are
1)the shelf slot is empty?if yes it overwright the name of the product and the “ideal price”
if not it do the sencond check
2)is the product present in the slot is the same of the box refil then it just go to the refill code else it print a debug line that say that is already occupied

then we have the refill code that is the part were I have the actual bug, basically what I did is to subtract the max slot space to the slot space avaliable(cause you can refill also if you have some product left), it get the min between the result and the remaning box product and then just set the quantity on the shelf with result of the min + quantity on the shelf
Then there is the check for the box that subtract the min to the box quantity and if the result is 0 or less(should not) it destry the box.
The problem is that, if like in picture, the box never get destroyed and the box stall at max quantity of the box and the quantity of the shelf and box are identical, while if I put a sequence on the 2 set the box get destroyed indipendently if is empty or not and still math is not done propierly

Hi, for me this is to much spaghetti :smiley:
An idea - to make the blueprint like the process is actually. So as far as i understand, you come with a box filled with x items and want to fill the shelf. When the box is empty after filling everything in, the box should be destroyed, right?
I would suggest to do this in a loop, so you have also the possibility to add some graphic or sound animation in the loop, while transfering the item from the box to the shelf.

In the debug i just printing remaining box and shelf quantity.

Also an advice to think more object orientated, if you have the box actor, this actor should hold the variable of box quantity. Then we can lower this variable and the actor itself can check if empty and destroy himself. Just think about you can loose some items on the way, or some other function, in this way you have the check for “destroy box” only once in the box actor.
Also later when you will have 100 of boxes, debugging is easier because you can find out the one box which get not destroyed for some reason.

thanks for the reply.
Your “code” is cleaner but still missing some parts cause with that(excluding the begin play) every time I trace a line and I hit a slot it will add things even if the shelf have already another product so you will have to do the check with branch anyway and then you are moving 1 object at time that is ok but you will run the same code more time for fill the shelf, that isn t “optimized” while in mine I move all in 1 time.
I have added to mine also another variable that is the result of the “min block” cause it look like that part of the bug is due to the fact that pure nodes execute every time they are called so having a variable that save the result should fix a part of the bug.
As said your code is cleaner and I will give it a chance but I have also to find out how to start the code with the correct event now…
Last thing, I have all the variable for the box quantity but they are called in way you can mix one with another.
Again thanks soo much, now I have to find out how to actually make it play(I used on clicked with a goofy cursor system that could not reach out the shipping segment of the game)

Update2
I found out how to start the code with the correct event, now it give me the correct output with the 1st interaction but the box explode even if 5 products are left in it, so I m trying to solve it.
I will update if I fix

Edit
Fixed it definitly, now it is working correctly, ma mate that said too many spaghetti was right :smiling_face_with_tear:
Now I have to make the box rotating or doing something that isn t a trace channel :laughing: , but this is fixed :+1:
I will post the fixed “code” :hand_with_index_finger_and_thumb_crossed:

For fixing that I had to add a enable input at the end of my grab system in the main char BP;
Here the full in product refill BP: