netlogo: how to make turtles stop for a set number of ticks then continue

前端 未结 2 2021
逝去的感伤
逝去的感伤 2020-12-21 01:24

I\'m trying to create a model where turtles walk randomly (but with a tendency for forward movement) until they land on a yellow coloured patch which represents a baited obj

2条回答
  •  渐次进展
    2020-12-21 02:02

    To answer just the part about "Only the observer can ASK the set of all turtles", that error message happens if you do:

    ask turtles [
      ask turtles [
        do-something
      ]
    ]
    

    This isn't allowed in NetLogo because it's almost always accidental rather than intentional. You probably just wanted each turtle to "do-something" once; you probably didn't mean for each turtle to "do-something" for every possible pair of two turtles.

    It's less obvious that you're having all turtles ask all turtles if it's split across procedures. So for example if you write:

    to go
      ask turtles [ my-procedure ]
    end
    
    to my-procedure
      ask turtles [ do-something ]
    end
    

    It's still wrong for the same reason, but it isn't as easy to see that just from glancing at it.

    Your code follows this latter pattern. You have:

    to move-turtles
      ask turtles [
        ...
        continue
        ...
      ]
    end
    
    to continue
      ask turtles [
        rt -90
        ...
      ]
    end
    

    I don't think you want to do ask turtles in the continue procedure. Since you call the procedure inside ask turtles, it's already a turtle procedure. I'd suggest writing it as:

    to continue  ;; turtle procedure
      rt -90
      ...
    end
    

    The comment reminds you that it's intended to be run by turtles. (We follow this style in all of the models in the Models Library.)

提交回复
热议问题