Help with the error: "OF expected input to be a turtle agentset or patch agentset or turtle or patch but got NOBODY instead."

907 views
Skip to first unread message

Karina Santos

unread,
May 7, 2021, 1:46:34 PM5/7/21
to netlogo-users
Hi all,

I have one problem with my code. I have the wrapping world disable with 5 colors and I want the turtles avoid the patches of blue color. But appears this error: "OF expected input to be a turtle agentset or patch agentset or turtle or patch but got NOBODY instead." Someone can help me? The code below. Thanks!


to setup5
clear-all
  set edge-size 10
  set-patch-size 50
  let pcolors []
  set pcolors [15 105 55 45 25]
  ask patches [
    set pcolor item (random 5) pcolors
    ]
  crt 1 [
    set size 1
    set color black
  ]
reset-ticks  
end

to go5
   ask turtles [
   ifelse [pcolor] of patch-ahead 1 = blue
    [ lt random-float 360 ]
    [ fd 1 ]
   if [pcolor] of patch-ahead 1 != nobody
    [ fd 1 ]
  ]
end

Karina Santos

unread,
May 7, 2021, 3:45:23 PM5/7/21
to netlogo-users
Hi all,

I forgot to put on code the global variable. So, I'm going to update the code (below). But, the error still persists. Thank you very much for all the help given :)

globals [ edge-size ]

to setup

clear-all
  set edge-size 10
  set-patch-size 50
  let pcolors []
  set pcolors [15 105 55 45 25]
  ask patches [
    set pcolor item (random 5) pcolors
    ]
  crt 1 [
    set size 1
    set color black
  ]
 reset-ticks
end

to go
   ask turtles [
   ifelse [pcolor] of patch-ahead 1 = blue
    [ lt random-float 360 ]
    [ fd 1 ]
   if [pcolor] of patch-ahead 1 != nobody
    [ fd 1 ]
  ]
end

Wade Schuette

unread,
May 7, 2021, 7:15:32 PM5/7/21
to Karina Santos, netlogo-users
I think you should compare an agent-set to nobody,  not a pcolor!

So try:

    ;; if there IS a patch ahead 1 step, test the color
    ;; otherwise turn ? 

    ifelse ( patch-ahead 1 != nobody )
       [   ;; there IS a patch 1 step ahead of some color
            ifelse [pcolor] of patch-ahead 1 = blue
               [ lt random-float 360 fd 1 ]
               [ fd 1 ]
      ]
      [   ;; there is NOT a patch 1 step ahead of any color
          ;  do something because there is no legal patch 1 step ahead of ANY color
     ]




--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/CABCtG4H9YP9XqihH8s1vzaQBZt%3DuCVnpBvsSBddaFYcoB9ezog%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages