2013-06-06 2 views
0

이 오류는 거북이를 목적지로 가져가는 가장 가까운 패치를 결정하려고 할 때 나타납니다.패치로이 코드를 실행할 수 없습니다.

this code can't be run by a patch 
error while turtle 0 running DISTANCE 
    called by procedure GO 
    called by Button 'go' 

이 문제가있는 코드 :

let nearest-patch min-one-of patches in-cone 1 180 [distance dest] 
     if not any? other turtles-on nearest-patch 
     [ face nearest-patch 
      fd 1 ] 

전체 코드 :

to go 
    reset-ticks 
    ask turtles 
    [ 
    ; going to the center, then goal 
    if dest = patch 0 0 and distance patch 0 0 < 3 
    [ repeat 5 [ fd 1 ] 
     set dest goal ] 

    ; wrapping around and going to the center, then goal 
    if distance goal < 3 
    [ repeat 5 [ fd 1 ] 
     set dest patch 0 0 ] 

     face dest 

    let nearest-patch min-one-of patches in-cone 1 180 [distance dest] 
    if not any? other turtles-on nearest-patch 
    [ face nearest-patch 
     fd 1 ] 

    ] 
    tick 
end 

도움말?

+1

위 코드를 실행했는데 goal = patch 0 0으로 오류가 발생하지 않았다. –

답변

0

당신의 최종 도착 및 목표를 사용하는 이유를 이해하지 못했지만, 어쨌든 난 당신의 코드는 처음 두 가지 문제가있다 생각 :

if distance goal < 3 

if distance 0 < 3을 의미합니다, 그래서 당신은 그것을 호출하기 전에 목표를 초기화되지 않았습니다를하는 (dest = patch 0 0 및 distance dest < 3)

패치가 거북 변수를 사용하려고 할 때 오류가 발생합니다 (오류가 발생하는 경우). , 나는 대개 거북 변수를 지역 변수에 저장하고 그것을 간접적으로 호출하지만, 더 나은 방법일지도 모른다. 나는 netlogo에 익숙하지 않다.)

turtles-own [dest goal] 
to setup 
    clear-all 
    create-turtles 10 [ 
    move-to patch random 15 random 15 
    ] 
end 
to go 
    reset-ticks 
    ask turtles 
    [ 
    ; going to the center, then goal 
    set dest patch 0 0 

    if dest = patch 0 0 and distance dest < 3 
     [ repeat 5 [ fd 1 ] 
     set goal dest ] 

    ; wrapping around and going to the center, then goal 

    if distance goal < 3 
     [ repeat 5 [ fd 1 ] 
     set dest patch 0 0 ] 

    face dest 
    let d dest 
    let nearest-patch min-one-of patches in-cone 1 180 [distance d] 
    if not any? other turtles-on nearest-patch 
    [ face nearest-patch 
     fd 1 ] 

    ] 
    tick 
end 
관련 문제