我想设置球权人,但是它不起作用,而是没有人。 这是我的代码:
to setup
clear-all
reset-ticks
setup-players-red
setup-players-blue
setup-ball
print BALL-OWNER
end
to setup-ball
create-balls 1 [
setxy 5 -1
set shape "ball basketball"
set size 2.5
set the-ball self
set BALL-OWNER one-of players with [distance the-ball = 0]
set owner BALL-OWNER
]
end
to setup-players-red
create-players 1[
set color red
set shape "person"
set size 5
setxy (5)
setxy (-1)
set team "red"
]
end
to setup-players-blue
create-players 1[
set color blue
set shape "person"
set size 5
setxy (-5)
setxy (1)
set team "blue"
]
end
那么,为什么我要打印“ nodoby”而不是玩家1/2? 我究竟做错了什么? 我还尝试将
”将[球距离= 0]设置为拥有一员的BALL-OWNER”。
在设置语句中,但我得到相同的结果。
答案 0 :(得分:2)
如果可能,请尝试以Minimum, Complete, and Verifiable Example的形式提交代码,以便用户可以将您的代码复制并粘贴到空白的NetLogo实例中并运行您的模型。
您为玩家使用的setxy
代码是有问题的-如果已解决,则不会出现与您描述的错误相同的错误-以下代码将为我运行:
globals [ ball-owner the-ball owner ]
breed [ players player ]
breed [ balls ball ]
players-own [ team ]
to setup
clear-all
reset-ticks
setup-players-red
setup-players-blue
setup-ball
print BALL-OWNER
end
to setup-ball
create-balls 1 [
setxy 5 -1
set shape "circle"
set size 2.5
set the-ball self
set BALL-OWNER one-of players with [distance the-ball = 0]
set owner BALL-OWNER
]
end
to setup-players-red
create-players 1[
set color red
set shape "person"
set size 5
setxy 5 -1
set team "red"
]
end
to setup-players-blue
create-players 1[
set color blue
set shape "person"
set size 5
setxy -5 1
set team "blue"
]
end