user3188146
user3188146

Reputation: 133

How to control a turtle through global variables on Netlogo

I was working on a project on Netlogo that creates a maze and I wanted to code it so that if the moving turtle hits a non-moving turtle (representing an obstacle-like thing) at another spot, then it opens up a "mini game" that I will create. However, when I include more turtles and use ask turtle 0 in my buttons so that the other turtles don't move and remain obstacles, everything begins to lag. How would I be able to use global-variables to solve the problem?

Upvotes: 2

Views: 1668

Answers (1)

Marzy
Marzy

Reputation: 1894

This is the same model using two breeds:

breed [Walls wall]
patches-own [is-wall]
breed [Humans person]
Humans-own [target]

to setup
  clear-all
  set-default-shape Walls "tile brick"
  set-default-shape Humans "person"
  set-patch-size 25


  create-humans 1 [
    set heading 90 
    set color white 
    move-to patch -5 -5 
    set target one-of patches with [not any? walls-here]
    ask target [set pcolor green]]
  set-walls
  reset-ticks
end

to set-walls
  ask n-of 10 patches with [not any? humans-here] 
  [
    set pcolor red
    sprout-walls 1 
    [ 
      set color brown
    ] 
  ]
end

to go
  ask humans [ 

    ifelse pcolor != green 
      [
        ifelse [pcolor] of patch-ahead 1 != red
        [
          Your-Move-Function
        ]
        [
          Your-Bounce-Function 
        ]

        leave-a-trail  
      ]
      [
        stop

      ]


  ]


  tick
end


to Your-Move-Function
  let t target 
  face min-one-of all-possible-moves [distance t]
  fd 1
end

to Your-Bounce-Function 
  let t target 
  face min-one-of all-possible-moves [distance t]
end

to-report all-possible-moves
  report patches in-radius 1 with [not any? walls-here and distance myself  <= 1 and distance myself  > 0 and plabel = "" ]
end

to leave-a-trail
  ask patch-here [set plabel ticks]
end

enter image description here

enter image description here

Upvotes: 2

Related Questions