My ifelse statement's result depends on the actions for true/false?
Currently I am building a route for a truck to drive inside my netlogo-land. When the truck is next to the shop-patch where it should deliver, the truck needs to change its actions.
However my if
or ifelse
statement does not seem to respond well and the answer depends on the output. With some tests:
*turtles> ifelse ((patch (first dirx) (first diry)) = one-of neighbors4) [write "11"] [write "22"]
"11"*
*turtles> ifelse ((patch (first dirx) (first diry)) = one-of neighbors4) [write "111"] [write "122"]
"122"*
*turtles> ifelse (patch (first dirx) (first diry)) = one-of neighbors4 [write "111"] [write "122"]
"122"*
*turtles> ifelse (patch (first dirx) (first diry)) = one-of neighbors4 [write "11"] [write "12"]
"12"*
*turtles> ifelse (patch (first dirx) (first diry)) = one-of neighbors4 [write "11"] [write "22"]
"11"*
Please note that during this time I do not move my tr开发者_开发知识库uck, I use the command center to ask these questions (from turtle truck perspective).
I am very confused about this. As the only thing I change is the action (what to write). This should not impact the true/false statement itself.
Does anybody have any clue what is going on here and why the ifelse
responds strange?
It's because the one-of
randomly chooses one of its arguments and returns that one.
neighbors4
returns an agentset with 4 patches (the ones N,S,E, and W of the turtle's patch). Thus, one-of neighbors4
will randomly choose from among these 4, so it might return a different value each time you call it.
精彩评论