Netlogo 如何将全局变量设置为补丁的pxcor或pycor?

Netlogo 如何将全局变量设置为补丁的pxcor或pycor?,netlogo,Netlogo,我想保存下一个补丁的位置,作为全局变量使用,这样我就可以引用它,比如在position shift中,这样我就可以在它接近世界边缘的情况下修改它。然而,我用来执行补丁所做的任何事情的代码是在observer模式下执行的,其中包含设置位置和位置偏移 错误显示,patch at仅在海龟/补丁上下文中,而设置位置在观察者上下文中 (不确定,但位置移动是否会出现类似错误?) 设置位置 将补丁的nextXcor[pxcor]设置为0-5 将补丁的nextYcor[pycor]设置为0-5 换位 结束 到位

我想保存下一个补丁的位置,作为全局变量使用,这样我就可以引用它,比如在
position shift
中,这样我就可以在它接近世界边缘的情况下修改它。然而,我用来执行补丁所做的任何事情的代码是在
observer
模式下执行的,其中包含设置位置和位置偏移

错误显示,
patch at
仅在海龟/补丁上下文中,而
设置位置
在观察者上下文中

(不确定,但
位置移动是否会出现类似错误
?)

设置位置
将补丁的nextXcor[pxcor]设置为0-5
将补丁的nextYcor[pycor]设置为0-5
换位
结束

到位置移位
如果nextYcor=-15
[将补丁的nextXcor[pxcor]设置为3 30
将补丁的nextYcor[pycor]设置为3 30]
如果nextXcor=15且nextYcor=-15
[用户消息“已达到空间限制。请按停止继续。”停止]
结束


Q:我应该如何修复
set position
和潜在的
position shift
的代码,以便全局变量
nextXcor
nextYcor
可以保存下一个补丁的位置以供使用?

如果可行,通常最好直接使用补丁

globals [nextPatch]

to test
  ;first test
  set nextPatch one-of patches
  position-shift
  ;second test
  set nextPatch (patch 0 -15)
  position-shift
  ;third test
  set nextPatch (patch 15 -15)
  position-shift
end

to position-shift
  if ([pycor] of nextPatch = -15) [
    if ([pxcor] of nextPatch = 15) [
      user-message "Space limit reached. Press 'OK' to continue or 'Halt' to stop." 
    ]
    set nextPatch (patch 3 10)
  ]
  ;remove the next line
  print nextPatch
end

如果可行,通常最好直接使用修补程序

globals [nextPatch]

to test
  ;first test
  set nextPatch one-of patches
  position-shift
  ;second test
  set nextPatch (patch 0 -15)
  position-shift
  ;third test
  set nextPatch (patch 15 -15)
  position-shift
end

to position-shift
  if ([pycor] of nextPatch = -15) [
    if ([pxcor] of nextPatch = 15) [
      user-message "Space limit reached. Press 'OK' to continue or 'Halt' to stop." 
    ]
    set nextPatch (patch 3 10)
  ]
  ;remove the next line
  print nextPatch
end