views:

41

answers:

1

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 truck, 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?

+1  A: 

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.

Jose M Vidal