Reputation: 21
I want to do something for 20 ticks, but only if 2 turtles (different breeds and shapes) are on the same patch. However, what I want to do involves observer context items. If there any way possible to allow an observer function to be called in a turtle context function? Help is appreciated. Thanks! (players is a breed)
to function1
ask turtles with [shape = "car"]
[if any? players-here [shieldTurtle]]
end
to shieldTurtle
let startTicks ticks
if ticks <= (startTicks + 20)
[stop randomKill
stop randomDamage
stop randomSpeed]
end
Upvotes: 2
Views: 1737
Reputation: 9610
Following up on Seth's suggestion:
turtles-own [start-shield]
to setup
ask turtles [set start-shield -20]
end
to function1
ask turtles with [shape = "car"] [
if any? players-here [shieldTurtle]
]
end
to shieldTurtle
set start-shield ticks
end
to randomKill ;;turtle proc
if (ticks - start-shield < 20) [stop] ;;shielded turtle exits
doThis
doThat
end
etc.
Upvotes: 2