Error when unwrapping world: "OF expected input to be a turtle agentset or patch agentset or turtle or patch but got NOBODY instead."

54 views
Skip to first unread message

Unruh Lee

unread,
Jun 22, 2022, 11:34:13 PM6/22/22
to netlogo-users
I was experimenting with making the world not wrapped, and upon setup and go, this error appears: 

"OF expected input to be a turtle agentset or patch agentset or turtle or patch but got NOBODY instead." 

I'm guessing this might have to do with the following code: 

to turn-towards-resource  ;; turtle procedure
  set heading 0
  let best-amount 0
  let best-direction []
  ifelse [ cacao-crop = false ] of patch-ahead 1 [ ; if the patch ahead is not an owned cacao farm, let the first direction tested be the "best direction" so far.
    set best-direction [0]
    set best-amount resource-ahead
  ]....


Not sure how to deal with this. When the world is not wrapped, is it necessary to make an "if clause" to the effect "if any? patch-ahead..."?

Full code of model attached in case that's handy. 

Thanks!
Lee
resourceharvest_altered_6_22_22.nlogo

Charles Staelin

unread,
Jun 23, 2022, 10:36:37 AM6/23/22
to netlogo-users
That is likely the problem you are encountering and, yes, you do need to check for their being a patch ahead when you are working in an unwrapped world.  Because NetLogo evaluates conditionals in order, you could use
ifelse any? patch-ahead 1 AND [ cacao-crop = false ] of patch-ahead 1 [ 

BTW, you could also just use [NOT cacao-crop] instead of  [ cacao-crop = false ] , but that is just a matter of style.

Charles

Unruh Lee

unread,
Jun 23, 2022, 3:04:24 PM6/23/22
to Charles Staelin, netlogo-users
Thank you, Dale and Charles!

Lee

--
You received this message because you are subscribed to a topic in the Google Groups "netlogo-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/netlogo-users/Jm-umr_BEqs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/4bb5dac4-a97f-42f2-ba6d-e8b147699bd6n%40googlegroups.com.

Dale Frakes

unread,
Jun 23, 2022, 7:10:54 PM6/23/22
to Unruh Lee, netlogo-users
I believe that will happen with a turtle at the edge that's also facing that edge and then trying to get patch-ahead.

You might check for that condition and have those turtles rotate 180 or check if patch-ahead is NOBODY before trying to use it.

Dale
--
Dale Frakes
E-mail: dfr...@gmail.com ** Web: http://www.dalefrakes.com

"that white light is made of colors, that color measures light waves,
that transparent air reflects light...? It does no harm to the romance
of a sunset to know a little about it." -Carl Sagan

James Steiner

unread,
Jun 26, 2022, 8:17:06 PM6/26/22
to Dale Frakes, Unruh Lee, netlogo-users
Using CAN-MOVE? N  is the best way to casually see if a movement would take a turtle off the edge of the world, or to look ahead to see if there is a valid patch at that distance, as it avoids any use of patch-ahead N which could throw an error in some circumstances. 

You can also use

IS-PATCH? (Expression that might return "nobody")

Combined with PATCH-AT-HEADING-AND-DISTANCE, this is good for a turtle to look in a direction other than its heading. 




--
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/5D1F82BA-DD1E-411B-94B0-73C48ECCA657%40gmail.com.
Reply all
Reply to author
Forward
0 new messages