Search code examples
anylogic

How to create a recurring event that cancels a block and allows the agent to re-enter the same block


In my pedestrian model, I have a pedGoTo block called goToNearestExit. The targetLine of this block is determined through a function I have created called getNearestExit() which finds the closest 'exit' targetLine to the pedestrian at the time of it entering the pedGoTo block. I would like to create a recurring event every 5 seconds which cancels the pedGoTo block allowing the agent to leave via the exit port and re-enter the pedGoTo block. This is so that it can re-call getNearestExit() thus continuously updating its nearest exit. (Exits are opening and closing in my model at random times.)

I have tried to implement this but am getting an error saying 'ped cannot be resolved to a variable'. How can I fix what I have done so far:

enter image description hereenter image description hereenter image description here


Solution

  • First, learn about the magic lightbulb and what hints it gives you: https://benjamin-schumann.com/blog/magic-lightbulb

    You will see that an event does not know about ped. You can simply call goToNearestExit.cancelAll() to force all to redo their stuff