Netlogo在turtle上下文中调用观察者上下文函数

时间:2015-01-13 23:19:48

标签: netlogo

我想为20个蜱做一些事情,但只有2只龟(不同品种和形状)在同一个补丁上。但是,我想要做的是涉及观察者上下文项。如果有可能允许在乌龟上下文函数中调用观察者函数?感谢帮助。谢谢! (玩家是一个品种)

  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

1 个答案:

答案 0 :(得分:2)

跟进赛斯的建议:

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