ArgyL
ArgyL

Reputation: 5

Netlogo WITH expected a true/false value but got 0 instead

I am fairly new to Netlogo. I am trying to make my turtles act differently depending on their variables, however I get the runtime error WITH expected a true/false value but got 0 instead.

I already initialize a couple of turtles on a different procedure so there should not be any empty agentsets of turtles with the requested variables.

  to setup-figures

    ask n-of 2 citizens
         [ get-panicked ]

    ask n-of 2 citizens
          [ get-alerted ]

    ask n-of 2 citizens
          [ calm-down ] 

  end

    to flee

    ask citizens with [ panicked? ] [

        fd 1.1
      ]

    ask citizens with [ alerted? ] [
        fd 0.6
       ]
    ask citizens with [ calm? ] [

         fd 0.5
       ]

    if [pcolor] of patch-ahead 1 = grey

      [collision-check]

end

to get-panicked

   set panicked? true
   set color red
   set mood 19

end

to get-alerted

   set alerted? true
   set color yellow
   set mood 35

end

to calm-down

   set calm? true
   set color green
   set mood 66

end

Upvotes: 0

Views: 1202

Answers (1)

Charles
Charles

Reputation: 4208

The ask primitive will look at all citizens to find those with (say) alerted? equals true. But if you only initialize some citizens, those not initialized will have alerted? set to its default value of zero. Zero and false are not the same in NetLogo, so ask chokes on those citizens whose value of alerted? is zero, i.e., on those that have not be initialized. At the beginning of your setup, you can put

ask citizens [
set panicked? false
set alerted? false
set calm? false
]

Then you can ask n-of your citizens to become panicked, etc., as you do in your code.

Upvotes: 1

Related Questions