我想创建一个数组调用Jobarray的列表,但是,当我尝试这样做时,netlogo会返回以下错误:
Extension exception: not an array: 0
error while job 470 running ARRAY:ITEM
called by procedure JOBLIST
called by procedure PLACE-JOBS
called by procedure SETUP
called by Button 'Setup'
这些是我的代码
to setup
ca
place-jobs
print Jobarray
reset-ticks
end
to set-job-index
let columns 3
let rows-job Number-Of-Jobs set
Jobarray array:from-list n-values rows-job [array:from-list n-values columns [0]]
end
to Joblist [#col #row #val]
array:set (array:item Jobarray #row) #col #val
end
to draw-pods
;draw pods area
ask patches with [(pxcor mod 4 = 2 or pxcor mod 4 = 3) and (pycor mod (Pod-size + 2) > 1 and pycor < (max-pycor - 4))]
[
sprout 1
[
set shape "square"
set color blue
stamp
die
]
set meaning "pods"
]
end
to place-jobs
let Job-index 0 ;; row of list; 0 == 1
ask n-of (Number-Of-Jobs) patches with [meaning = "pods"]
[
sprout-jobs 1
[
Joblist 0 Job-index who
Joblist 1 Job-index pxcor
Joblist 2 Job-index pycor
set Job-index (Job-index + 1)
set shape "square"
set color pink
set job-value 1
stamp
; die
]
set meaning "jobs"
set Jobnum (count jobs-on patches with [meaning = "jobs"])
]
end
任何人都可以帮我解释为什么以及如何解决这个问题?我已经尝试过搜索谷歌和字典,但仍然不明白为什么。 此致 胡志明
答案 0 :(得分:3)
看起来Jobarray
尚未初始化。我认为您在创建代理商时忘记致电set-job-index
。