Jesse001
Jesse001

Reputation: 924

Make turtles move ONCE according to their ranked order in a list

This question is built off my previous 2. I've been working to get a rank-ordered list for my turtles, ranked by an owned factor. They're then required to move in ranked order. That part works perfectly fine, and the code can be found at: Assigning turtles a ranked number in netlogo

The problem: using that code, they're moving in the correct order but instead of moving once, the program seems to be continuously re-running it for every turtle in the list so the first turtle in a world of 10 ends up moving 10 times, the second moves 9 times, etc.

I'm completely stumped on this, but I need it to stop. They're supposed to move once and be done for that tick. Ideas?

The list creation code is:

let rank-list sort-on [sociability] turtles
    let ranks n-values length rank-list [ ? ]  
   (foreach rank-list ranks [ask ?1 [set social_rank ?2] ] ) 
;;you can replicate the problem with this movement proc, or the full code in the link above       
 ask turtles [foreach rank-list [ask ? [set heading 270 forward 1]]]

Upvotes: 1

Views: 129

Answers (1)

Nicolas Payette
Nicolas Payette

Reputation: 14972

In the line:

ask turtles [foreach rank-list [ask ? [set heading 270 forward 1]]]

You're asking each turtle to execute a command for each turtle in your rank-list.

Just drop the ask turtles part.

As a more general note: foreach is to lists what ask is to agentsets. They both do the same basic thing, which is to perform a command for each item of a "collection". Agentsets are unordered collections of unique agents. Lists are ordered collections of possibly duplicated items of any type.

Upvotes: 2

Related Questions