How can I postpone action a tick later in Netlogo?

Viewed 49

I am trying to model a patch (represents environment). When its resources run off, they are regenerated with a tick's delay (tick + 1). How can I do that?

The idea is something like this:

if resources-amount = 0 
(tick + 1) ask patches [set resources-amount (resource-amount + 1 )]
1 Answers

You could add a patches-own variable regrow-time. It will be automatically intitialized as 0. If the patch looses all it's resources (during this tick), you can set the regrow-time to the number of ticks, you want, e.g. 4 ticks later:

  ask patches 
  [
    loose-resource
    if resources-amount = 0 and regrow-time = 0
    [
      set regrow-time ticks + 4
    ]
  ]

Then you can ask the patches, whose regrow-time has come, let them gain the resource and reset the timer to 0, so that the procedure eventually can start again.

  ask patches with [regrow-time = ticks]
  [
    gain-resource
    set regrow-time 0
  ]
Related