在我的模型中,龜的數量是基於用戶使用滑塊定義的值的動態值。滑塊可以取值在2到10之間。每個烏龜都有自己的一組座標和特徵,因此我使用下面的代碼來創建它們。Netlogo中的動態圖表
create-parties 1
[set color red set label-color red set label who + 1 set size 3 setxy party1-left-right party1-lib-con ]
create-parties 1
[set color green set label-color red set label who + 1 set size 3 setxy party2-left-right party2-lib-con ]
if Num-of-parties >= 3
[ create-parties 1
[set color blue set label-color red set label who + 1 set size 3 setxy party3-left-right party3-lib-con ] ]
我已經重複上述,直到Num-of-parties = 10。
在其中一個模塊中,我創建了一個條件,如果某個值達到0的龜就會死亡。
在我用一套電流積創建使用下面的代碼圖表模型的後面部分:
set-current-plot "Voter Support"
set-current-plot-pen "Party1"
plot 100 * [my-size] of turtle 0/sum[votes-with-benefit] of patches
set-current-plot-pen "Party2"
plot 100 * [my-size] of turtle 1/sum[votes-with-benefit] of patches
if Num-of-parties >= 3 [ set-current-plot-pen "Party3"
plot 100 * [my-size] of turtle 2/sum[votes-with-benefit] of patches ]
等等等等所有十個可能的海龜。
問題是,如果用戶在刻度10處定義了5只烏龜和3只烏龜,那麼由於沒有烏龜3,但是由於用戶定義的烏龜數量有限,因此代碼的一部分會拋出錯誤值爲5.
請告知如何解決此問題。謝謝,感謝幫助。
問候
非常感謝你的幫助。 – Yuvaraj