NetlogoBird
NetlogoBird

Reputation: 21

Netlogo hide-turtle

Here's a Netlogo-beginner question. I created a model where birds shall fly on a certain route. I created this route by placing 10 turtles I called "rasts" (resting place) on patches an linking them with each other. Now, I want to make the birds fly on these routes and when a resting place disappears (by using an "on/off"-switch), they shall take another route. My problem: At the moment I have 5 rasts but only the first one can be shut off by using the switch. Has anybody an idea, how to fix this?

Here's my code:

breed [rasts rast]
breed [birds bird]

to setup
 setup-rasts
 hide-rasts1 
 hide-rasts2 
 hide-rasts3 
 hide-rasts4
 hide-rasts5
end 

to setup-rasts
 set-default-shape rasts "circle"                  
 create-rasts 1 [setxy -12 36 ]
end

to hide-rasts1                                        
 ifelse rast-1? [ ask rast (number-of-birds + 0) [ set hidden? true] ]
               [ ask rast (number-of-birds + 0) [ set hidden? false] ]
end

Upvotes: 1

Views: 1328

Answers (1)

bergant
bergant

Reputation: 7232

For the first question:

  1. Isn't it possible to make more than 1 turtle hide itself by using the following code?

you can ask a list of turtles to hide:

; hide all turtles
ask turtles [ hide-turtle ]
; hide all your "rasts"
ask rasts[ hide-turtle ]
; hide random 4 of your turtles
ask n-of 4 turtles [ hide-turtle ]

As for the 2. question

  1. Is it possible to make turtles (birds) follow a route an change it, when there's another turtle (rast) in there way?

the answer is of course it is possible, but the question is somehow to general to suggest a precise solution. You can use the face command to point the turtle in the right direction. For sensing the nearest turtles check the turtles with min distance. For example (in turtle's context):

set nearest-rast min-one-of (other rasts) [ distance myself ] 

Upvotes: 2

Related Questions