Search code examples
netlogo

Why do I have a runtime error in my Go Procedure?


I'm not sure where of why I am getting a runtime error associated with the citizen-movement action. The employee-movement action does not trigger a runtime error. Here is the error:

OF expected input to be a turtle agentset or patch agentset or turtle or patch but got NOBODY instead. error while citizen 33 running OF called by procedure CITIZEN-MOVEMENT called by procedure GO called by Button 'go'

to go
  
  employee-movement
  citizen-movement
 
 tick 
end


to employee-movement
  
  ask employees [
   ifelse [pcolor] of patch-ahead 1 = black 
    
    [ rt random-float 360]  
    [ forward 1 ]
  ]
    
end


to citizen-movement
  
  ask citizens [
   ifelse [pcolor] of patch-ahead 1 = grey 
    
    [ rt random-float 360]    
    [ forward 1 ]
  ]
    
end

Solution

  • Is your world wrapping turned off? This error can happen if you have world wrapping off and a turtle is facing the edge. In that case, the primitive patch-ahead doesn't have any patch to refer to, so it returns NOBODY.