Sunny Boyd
Sunny Boyd

Reputation: 15

Netlogo: interogating other agents' variables

I am trying to ask agents to make decisions based on whether another agent's variable falls between the first agent's personal min and max. I am having trouble with the syntax expected by netlogo.

This bit, in the full code below:

to settle-decision
  ask turtles [
    ifelse ( myneighbor mycall ) > myminthresh AND myneighbor mycall < mymaxthresh)
      [ set settled? true ]
      [ set color yellow ]

Eventually I want to make the agents do more interesting things than change colors but I can't get past this one first! Any help most appreciated.

turtles-own [
  myneighbor                                 ;; closest other male frog to myself
  mycall                                     ;; the amplitude (loudness) of my own call
  myminthresh                                ;; when my neighbor's call is below this threshold, I move toward him
  mymaxthresh                                ;; when my neighbor's call is above this threshold, I move away from him
  myNND                                      ;; the distance to my nearest neighbor
  settle?                                    ;; true if male decides to create a territory and stop moving

 ]


to setup

  clear-all
  create-turtles population [                         ;; use the population slider to choose number of males

set size 1.5                                      ;; easy to see but is it actual agent size or just agent image size?
setxy random-xcor random-ycor                     ;; distribute frogs randomly in the landscape

set mycall random 100                             ;; choose the amplitude of my own call from a random distribution 0 to 100
set color scale-color red mycall 0 100            ;; allows easy visualization of variability in call amplitude
                                                  ;; lighter color is a higher amplitude
set myminthresh inputminthresh                    ;; use the input on interface to set the min-threshold
set mymaxthresh inputmaxthresh                    ;; use the input on the interface to set the max-threshold
set myNND 0                                       ;; initialize nearest neighbor distance for all

  ]

  reset-ticks

end

to go
  choose-neighbors
  settle-decision
  move-turtles
  tick
end

to choose-neighbors
   ask turtles [
    set myneighbor min-one-of other turtles [distance myself]  ;; choose my nearest neighbor based on distance
    set myNND distance myneighbor

  ]
end


to settle-decision
  ask turtles [
    ifelse ( myneighbor mycall ) > myminthresh AND myneighbor mycall < mymaxthresh)
    [ set settled? true ]
    [ set color yellow ]
  ]
end

to move-turtles
  ask turtles [
    face myneighbor
    ifelse mycall < myminthresh
        [ set color blue ]
        [ set color yellow ]
                                                              ;; this works but everybody moves so needs more work
    fd 5
    pendown
  ]
end

Upvotes: 1

Views: 59

Answers (1)

JenB
JenB

Reputation: 17678

The primitive you need is of with code like [variablename] of agent. I can't test this, but probably instead of:

to settle-decision
  ask turtles [
    ifelse ( myneighbor mycall ) > myminthresh AND myneighbor mycall < mymaxthresh)
    [ set settled? true ]
    [ set color yellow ]
  ]
end

try

to settle-decision
  ask turtles [
    ifelse ([mycall] of myneighbor > myminthresh) AND ([mycall] of myneighbor < mymaxthresh)
    [ set settled? true ]
    [ set color yellow ]
  ]
end

Upvotes: 1

Related Questions