netlogo - Initialization and termination of Turtles timer -


in procedure want start timer every turtles (agent) when change shape "shape2" "shape1", , timer expire after 10 ticks , shape changes "shape1" . procedure works when hit "go" works first 10 ticks counted. after not called. have called procedure name "change" in go block.

to change     let test one-of breed-here [ shape = "shape2" ]     if test != nobody , [ ticks ] of test = 10     [ask breed [ shape = "shape2" ]         [ set shape "shape1" ]     ] end 

the go block statement :

to go ask breed [ shape = "shape2" ] [ change ] end 

here illustration using patches. (colors stand in shapes.)

patches-own [shape-timer] globals [s1 s2]  setup   ca   set s1 blue     ;"shape" 1   set s2 red      ;"shape" 2   ask patches [set pcolor one-of (list s1 s2)] end  temp-change-shape   set pcolor s2   set plabel "temp"   set shape-timer 10 end  update   set shape-timer (shape-timer - 1)   if (shape-timer = 0) [     set plabel ""     show "changing back!"      set pcolor s1   ] end  go   ask patches [pcolor = s2 , shape-timer > 0] [     update   ]   ask one-of patches [pcolor = s1] [     temp-change-shape   ] end 

a nicer solution uses table extension, mapping dates (ticks) agents need updated @ each date. (that way don't have check each agent each tick find out if it's time update it.)


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -