2017-06-01 48 views
0

我想创建数组列表调用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 

谁能帮我解释一下我为什么,我该如何解决?我试过搜索谷歌和字典,但仍不明白为什么。 此致 Minh

回答

3

看起来好像Jobarray未被初始化。我想你在创建代理时忘了拨打set-job-index

+0

哦,我明白了,谢谢了很多:d –

+1

没问题!确保标记答案正确,以便其他人知道这个问题已被回答。 –