you cant use tick in a turtle context because tick is observer only!! NETLOGO

Viewed 4565

If i add if to my go command i get the error message

you cant use tick in a turtle context because tick is observer only

here is my go commands. search eat go-home and den are all defined in my commands.

energy is also defined as a global variable that turtles own

to go

  if ticks = day-length  [set day day + 1 create-next-day]


  ask adults [search eat]
  if energy < 20000 [ask adults [go-home den]]

 tick 

end

if i take out the line

if energy < 20000 [ask adults [go-home den]]

it runs perfectly, but i need that line or an equivalent. please help

Commands
;;-------------------------------------------------------------;;
;;------------------- ADULTS COMMANDS--------------------------;;
;;-------------------------------------------------------------;;

;; Need to add a private variable (wolves own) for wolves [state] and then need to code 4 states 1. Den 2. Search 3. Eat 4. Return
;; need to code all 4 states
;; Need to correctly allocate energy and the state of decline

To den ;when wolf is full
  set energy  energy  - .04
end


to search ;when wolf is hungry
  set energy  energy  - .07
    fd v-wolf
   if random 600 = 1 ;; frequency of turn
  [ ifelse random 2 = 0 ;; 50:50 chance of left or right
    [ rt 15 ] ;; could add some variation to this with random-normal 45 5
    [ lt 15 ]] ;; so that it samples from a dist with mean 45 SD 5

  ;; check if it can see a prey/food item
  ;; here i think we probably pick one of several possible prey
  ;; that are detectable randomly using the one-of command.
  ;; We should probably select the nearest one instead ** The turtles are getting
  ;; caught between two prey species and dying because they cant choose which one **
  if any? prey in-radius smell [set heading towards one-of prey in-radius smell]
  if energy < 0 [die]

end


To eat ;to kill prey and eat it
  let kill one-of prey-here in-radius smell
  ;need to code in a variable for success too
  if kill != nobody
    [ask kill [ die ]
      set energy energy + 10000]
end



to go-home ;to head home after they've eaten and den until they need to feed again
 if energy > 30000 [set target-patch min-one-of (patches  with [pcolor = white]) [distance myself]]
  face target-patch
  fd v-wolf
  set energy  energy  - 1
end
2 Answers
Related