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 install into "to setup" programming space at the beginning 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.
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
]
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
]