Reputation: 1
I have defined a blah?
as a property of a turtle under turtles-own
.
now in the to go
i want turtles with blah? property to do something and I want turtles without blah? property to do something slightly different.
For example:
ask turtles with [blah?]
[forward 2]
ask turtles with [not blah?] ; this won't work but i am trying to figure out how to do this
[forward 1]
so ask turtles with [not blah?]
won't work; how can I do that>
Upvotes: 0
Views: 133
Reputation: 2926
For what I can guess, the problem must be of the sort that you define blah?
as TRUE
for the turtles whose blah?
is true, but you do not define it as FALSE
for the turtles whose blah?
is false. This would result in some turtles having blah? = TRUE
, and some others having blah? = 0
(because 0 is the default value in NetLogo for all custom variables).
This would cause not
to give an error, because not
expects a boolean value but it finds a 0
instead.
The solution is to define blah?
for all turtles, and not only for those who should have it as true:
turtles-own [
blah?
]
to setup
clear-all
create-turtles world-height [
setxy (min-pxcor) (who + min-pycor)
set heading 90
ifelse (random 2 < 1)
[set blah? TRUE
set color yellow]
[set blah? FALSE
set color cyan]
]
end
to go
ask turtles with [blah?] [
forward 2
]
ask turtles with [not blah?] [
forward 1
]
end
A suggestion: it would probably be better to use one ask
command-block coupled with ifelse
(overall: n turtles being asked, n conditions being evaluated), rather than two ask
command-blocks both using with
(overall: n turtles being asked but 2n conditions being evaluated).
The go
procedure would look like:
to go
ask turtles [
ifelse (blah?)
[forward 2]
[forward 1]
]
end
Upvotes: 2