Talha
Talha

Reputation: 1

Stopping whole button with one turtle in Netlogo

I have a an amount of turtles that are going forward on a certain color. What iam trying to do is when only one turtle reaches to a different color I want the forever button to stop so i can see how many ticks it took for that turtle to get there

to go_wiggle_wet
  ask turtles [
    if pcolor = blue [stop]
    lt random wiggleleft
    rt random wiggleright
    fd difflength
  ]
  tick
end

Upvotes: 0

Views: 27

Answers (1)

Luke C
Luke C

Reputation: 10301

Easiest might be to have a variable that can act as a "flag" to indicate whether the condition you're after has been met. For example, below I've created a variable called found-target? that all turtles initially set to false. Once a turtle finds a green patch it sets found-target? to true, and on the next call of go that is evaluated with if any? turtles with [found-target?] and the button can be stopped:

turtles-own [ found-target? ]

to setup
  ca
  crt 10 [ 
    pd
    set found-target? false
  ]
  ask n-of 200 patches with [ distancexy 0 0 > 10 ] [
    set pcolor green
  ] 
  reset-ticks
end

to go ; assuming this is the forever button
  if any? turtles with [ found-target? ] [
    print ticks
    stop
  ]
  ask turtles [
    rt random 61 - 30 
    fd 1
    if pcolor = green [
      set found-target? true
    ]
  ]
  tick
end

Upvotes: 1

Related Questions