Comment 32 for bug 409654

Revision history for this message
Al Riddoch (alriddoch) wrote :

Now that I have started debugging Fishing.tick_operation, I have discovered all sorts of things wrong with it:

1) You try/except block is hiding all the errors from you.

2) "bait" is uninitialised in tick_operation. You need to store then ID of the bait entity when the task is initalised with something like this:

    self.bait_id = bait.id

then in the tick_operation function, you can get the actual bait object with:

    bait=server.world.get_object(bait.id)

The first time tick_operation is called is the first opportunity for you to discover the ID of the hook entity, so you need to determine that, and store it for future use. Next time tick_operation is called, then bait entity may no longer exist, as it gets destroyed when it gets eaten.

3) You cannot have a long term loop in a task method, as it will block everything in the whole server. The server is a single thread of execution. You have to do all the checks you can, then return a tick to be called again, using next_tick(). Once you have done the setup, which included discovering the hook ID, all that needs to be done in each call to tick_operation is to check whether the hook is inside the bait or not. As soon as it is no longer in the bait, you can then determine what it is inside, and that is whatever has been caught.

Is all this clear?