Netlogo: How can I install the “initial value” of the decrement-timer with specific conditions

北城余情 提交于 2019-12-12 04:52:31

问题


I would like to set a decrement-timer when the turtle reaches the end of the road (right end). (I would like to activate the decrement- timer only for the turtle that reached the left end of the road.) And keep turning the decrement-timer until the turtle dies under the specified conditions. The setting time ("A") of the decrement-timer is set separately. I made the following sample program. But the model does not work well. Because in this sample program the initial value of the decrement-timer continues to be set with every tick, if turtle is at the right end of the road. I would like to install the initial value of the decrement-timer when the turtle reaches the end of the road. Therefore, the initial value of the decrement-timer can not be instolled into "to setup" programming space at the begining of the model. When I install the initial value of the decrement-timer at "to setup", the initial value of the decrement-timer will remain in the log before the turtle reaches the end of the road. I want to avoid having troublesome counting of logs. Tanks you.

let carright one-of turtles-on patch max-pxcor 0
if carright != nobody [ 
  ask carright [ set count-down A ] ;this is the problem.
  ask carright [ set speed 0 ]
  ask carright [ set count-down count-down - 1 ]
]`

Hi Jen B, I made the following sample code with refering your sample code and tested it. However, the decrement counter did not move. I would be happy if you give me advice.

let onend? one-of turtles-on patch max-pxcor 0
ask turtles-on patch max-pxcor 0 
;;In this syntax "ask turtles with onend?" I got an error so I changed it.

[ if-else count-down > 0
  [ set count-down count-down - 1 ]
  [ 
    set gamma-A precision (random-gamma (α) (β))0
    if gamma-A <= 0 [
      die
      set number-of-turtles  number-of-turtles - 1
      set number-dead number-dead + 1
    ] 
  ]
]
ask turtles-on patch max-pxcor 0
;;I got an error in this syntax "Ask turtles - on patch max - pxcor 0 with not onend?", so I changed it.

[ set count-down A ;;This worked properly. 
  set speed 0 ;;This worked properly.
  set color red ;;This worked properly.
  set onend? TRUE
]

回答1:


I am still not clear what you are trying to do, but based on the comments discussion, this might be something closer than the code you have.

turtles-own [onend?]    ; note that you will have to set this to false in setup

ask turtles with [onend?]
[ if-else count-down > 0
  [ set count-down count-down - 1 ]
  [ die ]
]
ask (turtles-on patch max-pxcor 0) with [not onend?]
[ set count-down A
  set speed 0
  set onend? TRUE
]


来源:https://stackoverflow.com/questions/44479874/netlogo-how-can-i-install-the-initial-value-of-the-decrement-timer-with-speci

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!