No more starving snails

Dear jar capacity validator,

I’m sorry I ever doubted you. I thought you were killing my snails, but really it’s my lack of you that caused the problem. I am the one guilty of virtual snailslaughter.

Before you refuse to ever speak to me again, let me explain.

(Ok I’m stopping this now)

For the past couple of weeks my snails have been dying of starvation. I didn’t really notice that there was a problem straight away. After some digging I realized that the most delicious item in the jar I was using was at y pos 1180, but for some reason when the snails tried to approach it they never got there. This resulted with them trying to get to the item each minute, but never making it, and starving as a result.

There are two problems here. The most immediate problem is why aren’t the snail’s reaching the item? I quickly realized that this was because I run a jar position validation check before setting target positions for the snails. The max y and x positions are calculated based on the jar’s capacity. In this case, the jar’s capacity was 20. The max y pos of a snail within the jar was 20 * 50, so 1000. So during validation the snail’s targetPosY kept getting set to 1000 because that is the farthest the snail could go.

The problem, it turned out, was that I was doing zero jar posiion validation on the item itself. Something must have at some point set the y position for the item to 1180 (either the autogenerated random position when the item is dropped or maybe I dragged it weirdly on canvas). I manually moved that one item and added a check, so this should never happen again.

The second problem

The second problem became apparent due to this bug. If a snail can’t physically reach a consumable item to feed itself, it needs to switch attention to another item and try to reach it instead. In real life a snail wouldn’t keep beating its head against the glass trying to get the one piece of lettuce on the other side when there is lots of other lettuce sitting around in the jar itself, within easy reach! I will tackle this next.

comments powered by Disqus