johns4ta
johns4ta

Reputation: 896

Trying to check color patch ahead and make decision based on patch color of patch ahead

I am trying to have a turtle check the color of the patch ahead and make a decision on where to move. If the patch ahead isn't white then the turtle to rotate left or right and moves. I am getting an error in my If decision construct that says "Expected a TRUE?FALSE here, rather than a list of block". Any idea what might be causing it? I used the same logic for my while loops which seem to work fine. Below is my code and the error occurs in the first line of the code "ifelse [[pcolor] of patch-ahead 1 != white]".

 ifelse [[pcolor] of patch-ahead 1 != white][
     ifelse(tempx < xcor)[
       set heading 270
       jump 1
       ]
     [ 
       set heading 90
       jump 1
     ]
 ]

Thanks in advance!

Upvotes: 3

Views: 4698

Answers (1)

Jose M Vidal
Jose M Vidal

Reputation: 9142

You have a syntax error. The conditional in an ifelse should not be in a block.

Fix it as such:

ifelse [pcolor] of patch-ahead 1 != white [
....

Upvotes: 7

Related Questions