2013-12-08 59 views
2

我試圖讓我的龜改變補丁的顏色,當它與它接觸並嘗試下面的代碼:的NetLogo - 補丁的變化顏色,當代理處於頂部

to deesculateviolence 
    ask turtles [ 
    if pcolor = red [set pcolor blue] 
    ] 
end 

代碼不會出現任何錯誤,但是當我播放模型時,補丁的顏色不會改變。我已經嘗試了不同型號的類似代碼,但仍無法獲得修補程序來更改顏色。如果有人知道我要去哪裏,我會非常感謝你的幫助。

+1

謝謝。我已經將代碼添加到模型中,並且運行良好。我可以玩這個代碼並從這裏開始構建。非常感謝你 – user3078544

回答

3

我覺得你的代碼做正確的事:

to setup 

    clear-all 

    create-turtles 5 [ 
    move-to patch random 20 random 20 

    ] 
    ask n-of 25 patches [set pcolor red] 
    reset-ticks 
end 

to go 

    ask turtles [ 
    rt random 10 
    fd 1 

    if pcolor = red [set pcolor blue] 
    ] 
    tick 
end 

enter image description here

enter image description here

你可以看到在下面的例子中更好 enter image description here

enter image description here

效果
+1

爲了避免使用'__clear-all-and-reset-ticks',我已經編輯了這一點,它只存在於舊NetLogo版本的後向兼容性中。它不應該用在新代碼中。相反,在安裝開始時輸入'clear-all',在末尾輸入'reset-ticks'。 –

+0

謝謝,我不知道:) – Marzy