Reputation: 11
I'm trying to get a turtle to stop if they run out of energy as if they have died. when they have eaten the grass, however keep getting an error when attempting to use an if statement.
turtles-own [energy]
to setup
clear-all
setup-patches
setup-turtles
reset-ticks
end
to setup-patches
ask patches [ set pcolor green ]
end
to setup-turtles
create-turtles 100
ask turtles [ setxy random-xcor random-ycor ]
set energy energy + 10
end
to go
move-turtles
eat-grass
tick
end
to move-turtles
ask turtles [
if energy energy = 0 [ stop ]
right random 360
forward 1
set energy energy - 1
]
end
to eat-grass
ask turtles [
if pcolor = green [
set pcolor black
set energy energy + 10
]
]
end
Upvotes: 1
Views: 31
Reputation: 17678
you have repeated the variable name energy, just replace if energy energy = 0
with if energy = 0
Upvotes: 2