ACandia
ACandia

Reputation: 39

How to get turtle to wait at patch for 10 ticks

I would like my turtles to

1) Stop for ten ticks if the turtle is red and comes across a red patch 2) After ten ticks I would like the turtle to continue on the look-for-food subroutine, which I already have.

Upvotes: 2

Views: 559

Answers (1)

Nicolas Payette
Nicolas Payette

Reputation: 14972

An easy way to accomplish this is to use some sort of counter. Here is a full example:

turtles-own [ counter ]

to setup
  clear-all
  create-turtles 100 [
    set counter 0
    setxy random-xcor random-ycor
  ]
  ask n-of 25 turtles [ set color red ]
  ask n-of 100 patches [ set pcolor red ]
  reset-ticks
end

to go
  ask turtles [
    ifelse counter = 0 [
      look-for-food
      if color = red and pcolor = red [
        set counter 10
      ]
    ] [
      set counter counter - 1
      set label counter ; just to show what's going on
    ]
  ]
  tick
end

to look-for-food
  ; your own look-for-food procedure is presumably different
  right random 20
  left random 20
  forward 1
end

Upvotes: 1

Related Questions