Alexandra Casuso
Alexandra Casuso

Reputation: 11

NETLOGO Set a variable of an agent to something

I want to set variable P of one of the turtles with happy? = true to P - 9. This is what i have so far, but it is not working, any ideas?

set [P] of one-of turtles with [happy? = true] (P - 9)

Upvotes: 1

Views: 335

Answers (1)

nldoc
nldoc

Reputation: 1209

[P] of ... can only report the value of the turtles variable, but you are not allowed to change it because you are not in the turtles context. You have to call the turtle via ask to change its own variable:

   ask one-of turtles with [happy? = true]
    [
      set P (P - 9)
    ]

Upvotes: 1

Related Questions