Netlogo 您不能在海龟上下文中使用勾号,因为勾号仅用于观察者!!网络标志
如果将If添加到go命令中,则会收到错误消息 不能在海龟上下文中使用勾号,因为勾号仅用于观察者 这是我的围棋命令。搜索、吃、回家和书房都在我的命令中定义 能量也被定义为海龟拥有的一个全局变量Netlogo 您不能在海龟上下文中使用勾号,因为勾号仅用于观察者!!网络标志,netlogo,Netlogo,如果将If添加到go命令中,则会收到错误消息 不能在海龟上下文中使用勾号,因为勾号仅用于观察者 这是我的围棋命令。搜索、吃、回家和书房都在我的命令中定义 能量也被定义为海龟拥有的一个全局变量 to go if ticks = day-length [set day day + 1 create-next-day] ask adults [search eat] if energy < 20000 [ask adults [go-home den]] tick e
to go
if ticks = day-length [set day day + 1 create-next-day]
ask adults [search eat]
if energy < 20000 [ask adults [go-home den]]
tick
end
如果我把电话线拔出来
if energy < 20000 [ask adults [go-home den]]
它运行得很好,但我需要那条线或同等的线。请帮忙
Commands
;;-------------------------------------------------------------;;
;;------------------- ADULTS COMMANDS--------------------------;;
;;-------------------------------------------------------------;;
;; Need to add a private variable (wolves own) for wolves [state] and then need to code 4 states 1. Den 2. Search 3. Eat 4. Return
;; need to code all 4 states
;; Need to correctly allocate energy and the state of decline
To den ;when wolf is full
set energy energy - .04
end
to search ;when wolf is hungry
set energy energy - .07
fd v-wolf
if random 600 = 1 ;; frequency of turn
[ ifelse random 2 = 0 ;; 50:50 chance of left or right
[ rt 15 ] ;; could add some variation to this with random-normal 45 5
[ lt 15 ]] ;; so that it samples from a dist with mean 45 SD 5
;; check if it can see a prey/food item
;; here i think we probably pick one of several possible prey
;; that are detectable randomly using the one-of command.
;; We should probably select the nearest one instead ** The turtles are getting
;; caught between two prey species and dying because they cant choose which one **
if any? prey in-radius smell [set heading towards one-of prey in-radius smell]
if energy < 0 [die]
end
To eat ;to kill prey and eat it
let kill one-of prey-here in-radius smell
;need to code in a variable for success too
if kill != nobody
[ask kill [ die ]
set energy energy + 10000]
end
to go-home ;to head home after they've eaten and den until they need to feed again
if energy > 30000 [set target-patch min-one-of (patches with [pcolor = white]) [distance myself]]
face target-patch
fd v-wolf
set energy energy - 1
end
如果能量<20000[询问成年人[回家巢穴]]将是围棋中的一个问题,如果能量看起来是一个海龟变量。这将使过程的上下文成为海龟上下文,而不是观察者上下文
编辑:
例如,如果能量是一个海龟变量,也许你的意思是
ask adults [if (energy < 20000) [go-home den]]
首先,您需要更加渐进地构建代码。您的代码中有多个部分不起作用,您不理解。尝试添加尽可能少的量,并确保在添加任何其他内容之前都能正常工作。目前您有三个不同的问题,代码的不同部分都有错误
关于艾伦回答中的上下文问题,可以这样想:变量“能量”属于海龟。这意味着,如果你有10只海龟,你有10个名为“能量”的变量,每只海龟一个。您正在检查哪一个是否已根据您的请求进行了更新。那么我将如何修复它?
to go
if ticks = day-length
[ set day day + 1
create-next-day
]
ask adults
[ search
eat
if energy < 20000
[ go-home
den
]
]
tick
end