2016-05-28 7 views
1

「タートルズ(エージェント)」のシェイプを「シェイプ2」から「シェイプ1」に変更するときにタイマーを開始し、そのタイマーが10ティック後に期限切れになり、シェイプが元に戻ります「shape1」に変換する。私の手続きは、 "go"を押すと初めてカウントされた最初の10ティックだけ動作します。それ以降は呼び出されません。 GOブロックでこのプロシージャ名を「変更」と呼んでいます。タートルズタイマーの初期化と終了

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

GOブロック文は次のとおりです。ここで

to Go 
ask breed with [ shape = "shape2" ] [ change ] 
end 

答えて

1

は、パッチを使用して示す図です。 (色は形状のために立っている。)

patches-own [shape-timer] 
globals [s1 s2] 

to setup 
    ca 
    set s1 blue  ;"shape" 1 
    set s2 red  ;"shape" 2 
    ask patches [set pcolor one-of (list s1 s2)] 
end 

to temp-change-shape 
    set pcolor s2 
    set plabel "temp" 
    set shape-timer 10 
end 

to update 
    set shape-timer (shape-timer - 1) 
    if (shape-timer = 0) [ 
    set plabel "" 
    show "changing back!" 
    set pcolor s1 
    ] 
end 

to go 
    ask patches with [pcolor = s2 and shape-timer > 0] [ 
    update 
    ] 
    ask one-of patches with [pcolor = s1] [ 
    temp-change-shape 
    ] 
end 

よりよい解決策は、各日付に更新する必要があるエージェントにtable拡張、マッピング日付(マダニ)を使用します。 (そうすれば、各エージェントをチェックして、それを更新するかどうかを調べる必要はありません)

関連する問題