This is the way the bracketing would work (note that the spacing is not important for syntax, but I structured it so you could see where the code blocks start and end). I also added an
ask one-of followers [ if any? followers-at -41 -22 [ set breed leaders ] ]
ask is asking one of the turtles of the breed named ‘followers’ to do everything in the outer code block. The randomly chosen turtle then checks if there are any ‘followers’ on the patch at coordinates -41 -22 from itself (relative, not absolute). If there are, then the randomly chosen turtle (not the ones on the specified patch) changes its breed to leaders.
What you probably want is to have one of the followers on the patch change breed. That would look like:
if any? followers-on patch -41 -22 [ ask one-of followers-on patch -41 -22 [ set breed leaders ] ]
So I changed
turtles-at (relative) to
turtles-on (absolute) position, as well as going to the turtles on the relevant patch.
For efficiency (so set of turtles created only once instead of twice), debugging (so you don’t accidentally have different coordinates in the two places), a better way of doing this same code is:
let potential-leaders followers-on patch -41 -22 if any? potential-leaders [ ask one-of potential-leaders [ set breed leaders ] ]
As for finding out whether it’s the first, all you need to do is check that there aren’t any existing leaders as part of your conditions (eg
not any? leaders)
CLICK HERE to find out more related problems solutions.