user3344370
user3344370

Reputation:

Ask a different turtle for its variable

I'm new to Netlogo and have been chucked in at the deep end. Each turtle has a variable - colony, which is a number between 1-9. I'm wanting to get a turtle face towards its closest neighbour which has the same colony number as it does. It then moves (that bit works fine). At the moment I have

let newTurtle min-one-of other turtles [10]
let variableA [ask newTurtle [colony]]
ifelse colony = variableA newTurtle [face newTurtle] [rt random 360]
move-forward

This works and gets all turtles to move into 1 central location:

let newTurtle min-one-of other turtles [10]
face newTurtle
move-forward

What I've tried is to get a turtle to ask its neighbour for its colony, if there the same move towards, else move in random direction. "Expected a literal value" is currently the error regarding to the second line. I know this isn't exactly what I want but I can't get this working. Any help on this or my main problem would be appreciated!! Thanks

Upvotes: 2

Views: 2049

Answers (1)

Luke C
Luke C

Reputation: 10291

Your main problem might stem from your use of min-one-of in the first block. Check out the dictionary entry for that primitive and note that it requires a reporter as one of its parameters, so "[10]" doesn't work. Additionally, min-one-of actually asks for the lowest value of the reporter. So, I think you need to approach this a little differently. You could break this down into following steps. First, get the acting turtle to identify those turtles that are the same colony as it:

ask turtles [
    let my_colony other turtles with [ colony =  [colony] of myself ]

This would have the acting turtle create a temporary variable called "my_colony" that consists of all turtles in the world that belong to the same colony as the acting turtle. Then, you want the acting turtle to select the closest member of that group. In the same code block:

let target min-one-of my_colony [ distance myself ]

Here, the agentset for min-on-of is "my_colony", and the reporter is "[ distance myself ]", which returns the turtle that in "my_colony" with the smallest value of distance to the acting turtle. Next, check to make sure that the target exists; otherwise, if there is only one turtle in a specific colony, you will get an error. In the same code block still:

if target != nobody [
      face target
      fd 1
    ]

Hopefully that gets you started, let me know if anything needs clarification.

Upvotes: 2

Related Questions