Bradd112
Bradd112

Reputation: 43

Netlogo - Ordered Movement

I have the following error in Netlogo and I'm unsure why. I am trying to make the turtles move around in a ordered fashion but I keep getting an error when I change the d angle: "FACE expected input to be an agent but got NOBODY instead". Any help would be appreciated.

globals [Angles]
to setup
  clear-all
  create-turtles amount [ setxy random-xcor random-ycor ]

  ask turtles [
  set Angles (random 360)

]

  reset-ticks
end

to monitor
 show count patches
      show ticks
end

to go

  if (all? patches [pcolor = yellow]) [stop]
  ask turtles [

    face min-one-of patches with [ pcolor = black ] [ distance myself ]
    ;; This line of code tells the turtle to head towards the nearest patch containing the colour of black.
    set Angle  d  Angle * 1 - Angle
    rightt Angle
    forwardd 1




    ifelse show-travel-line? [pen-down][pen-up]
    set color red


    if pcolor = black [
      set pcolor yellow



    ]

  ]

tick
end

Upvotes: 0

Views: 136

Answers (1)

Alan
Alan

Reputation: 9620

You can unveil the problem but running this test:

to test
  ca
  crt 1
  let x -10E307 * 10
  show x
  ask turtle 0 [rt x]
  inspect turtle 0
end

You will see that the heading is NaN because you gave it a turn of -Infinity. Now if you move the turtle, the xcor and ycor will become Nan.

To avoid this problem, you need to limit the values taken by angle. For example,

globals [turn angle]

to setup
  clear-all
  set turn random-float 1
  create-turtles 10 [
    setxy random-xcor random-ycor
    set color red
    pen-down
  ]
  reset-ticks
end

to go
  if (all? patches [pcolor = yellow]) [stop]
  ask turtles [
    part1
    part2
    if pcolor = black [
      set pcolor yellow
    ]
  ]
  tick
end

to part1
    let _patches (patches with [ pcolor = black ])
    face min-one-of _patches [ distance myself ]
end

to part2
    set turn (4 * turn * (1 - turn))
    set angle turn * 360
    rt angle
    fd 1
end

Upvotes: 2

Related Questions