netlogo - Error: Element 287 of list [0] could not be found, which is only 1 in NetLogo
问题描述
I would like to quantify how many times each turtle has passed each patch in the world. Do you know how I can get this information from NetLogo? I was able to find out how many times the turtle visited the patches, but not how many times it went to each specific patch. For example: turtle 0 visited patch (0, 0) 2 times and patch (0, 1) 4 times. But,Turtle 2 visited patch (0 0) 3 times and patch (0, 1) 3 times and so on.
But, the following error appears: Element 287 of list [0] could not be found, which is only 1. error while patch 7 22 running ITEM called by (anonymous command: [ id -> let item id turtle-visits set turtle-visits replace-item id turtle-visits current-num-visits + 1 ]) called by procedure GO called by 'go' button
Can someone help me?
globals [ edge-size ]
patches-own [ turtle-visits ]
to setup
ca
let num-turtles 1
set edge-size 29
resize-world 0 edge-size 0 edge-size
let pcolors []
set pcolors [ 85 95 ]
ask patches [
set turtle-visits n-values num-turtles [0]
set pcolor item (random 2) pcolors
]
reset-ticks
end
to go
ask turtles [
rt random 360
fd 1
]
end
解决方案
问题是,您使用turtle-visits
每个补丁的海龟数量初始化列表,即num-turtles
:
set turtle-visits n-values num-turtles [0]
如果你替换num-turtles
为count turtles
,因为你想为世界上的每一个海龟都设置一个值,它应该可以工作:
set turtle-visits n-values count turtles [0]
推荐阅读
- vue.js - 无法加载 pdf - Vue
- sql - 如何映射(参考)相同的数据但不同的PK?
- javascript - 反序列化 JSON 数据并删除名称并仅返回值
- android - 使用 AudioTrack 播放 base64 编码的音频字符串(转换为字节数组)只会产生白噪声
- flutter - 如何捕获 http.get (SocketException)
- css - 在 Ant Design 中创建固定页脚
- python - 添加所有偶数斐波那契数
- php - Onesignal:included_segments 必须是字符串数组
- http - 取消 Http 处理程序请求
- python - sqlalchemy.exc.OperationalError:(sqlite3.OperationalError)没有这样的列:假