error: WITH expected this input to be an agentset, but got a patch instead

81 views
Skip to first unread message

Rafaela Lorena

unread,
Jun 2, 2021, 12:29:03 PM6/2/21
to netlogo-users
Hi,

I've been trying since yesterday to code the following: l have a world with 1 turtle in each patch (sprout command). I would like the turtle to check the 8 neighbors from the patch it is in. I did it like this: let neighWithVeg count neighbors of patch-here with [veg-value > 0.2]. But the error appears: WITH expected this input to be an agentset, but got a patch instead

Can someone help me?

globals [
  edge-size
]

patches-own [
  veg-value
]

to setup
  clear-all
  reset-ticks
  set edge-size 30
  set-patch-size 21
  ask patches [
   set pcolor green
    sprout 1
    ;set veg-values random min min-veg random max max-veg-dist
   set veg-value random-in-range -3 1
  ]
  ask turtles [
  set size 1
  set color black
  ]
end

to-report random-in-range [low high] ;; limit random-in-range
  report low + random (high - low + 1)
end
 
  to go
 ask turtles [
   neighboring
  ]
end

to neighboring
    let neighWithVeg count neighbors of patch-here with [veg-value > 0.2]
    ifelse neighWithVeg = 0
    [
      move
    ]

    [
      move-to one-of neighbors of patch-here with [veg-value > 0.2]
    ]  
end

vidus...@gmail.com

unread,
Jun 2, 2021, 9:16:55 PM6/2/21
to netlogo-users
Hi Rafael

When you say patch-here with [veg-value > 0.2], it looks at patch-here not the neighboring patches you just need to chnage a littel bit. 
Similar error you will find in line with move-to code. I think its better to store neighbors with [veg-value > 0.2]  in a tem. variable then you can call  it from next line of your code. 

see below your updated neighboring procedure:

to neighboring
  let myneighWithVeg [ neighbors with  [veg-value > 0.2] ]of patch-here   
  let neighWithVeg count [ neighbors with  [veg-value > 0.2] ]of patch-here 
  
    ifelse neighWithVeg = 0
    [
      move
    ]

    [
      move-to one-of myneighWithVeg
    ]  
end

to move
  
end 

Hope this helps.

Cheers 

Vidushi

Rafaela Lorena

unread,
Jun 2, 2021, 9:23:38 PM6/2/21
to vidus...@gmail.com, netlogo-users
Hi Vidushi,

Thank you for the help! helped a lot

Cheers

--
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/6c28081f-8b46-41aa-a05f-2a620ce290b3n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages