简体   繁体   中英

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)

[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)
    ]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM