colinsheppard / time

A NetLogo extension that brings date/time utilities and discrete event scheduling to NetLogo
12 stars 13 forks source link

Can't stop execution when there's a repeating event #25

Open SFRailsback opened 11 years ago

SFRailsback commented 11 years ago

I scheduled this: ; Schedule graphics updates once per tick, starting at tick 1. ; A check to keep the updates from happening eternally is in update-output time:schedule-repeating-event "observer" task [ update-output ] 1.0 1.0

Then try to stop the schedule this way:

to update-output ; An Observer procedure scheduled once per tick ; First, stop the schedule if no more balls are in the air. ; In that case, the schedule contains only one event: the output update. if time:size-of-schedule <= 1 [ time:clear-schedule ]

But the schedule keeps going forever. (even if I use <= 2, etc.)

colinsheppard commented 10 years ago

The problem is that the event is rescheduled after it is executed, so if you put "time:clear-schedule" inside the event, it will clear the schedule, but then when the procedure returns it get's scheduled again.

I previously used the "stop" primitive to terminate "time:go" but that was undesirable because stop usually means exit from the current procedure, not more.

For now, the solution to this problem is to use "time:go-until" instead of "time:go". The documentation already notes that mixing time:go with a repeating event can cause an infinite loop.

But I will keep this issue as an enhancement for a future release as it would be nice to have the ability to get out of execution. I'll probably add a new primitive "time:stop" to accomplish this.