Grace
Grace

Reputation: 3

NetLogo : Keep turtles moving continuously till the end

Readers,

I'm a beginner in NetLogo. Please help me in solving few issues with my code that is below:

  1. I'm getting an error "You can't use tick in a turtle context, because tick is observer-only.
  2. I need to get tick value updated after each turtle go all three of "arrive-reception, arrive-triage, go-drroom".
  3. the rest of people is not moving around the arrive reception, arrive triage is running.

    to setup-people
      set-default-shape turtles "person"
      set destination ( patch-set patch -2 34 patch 8 34 ) 
    
      create-turtles uninfected
      [ set color blue
        allocate-turtles        
      ]
    
      create-turtles infected
      [ set color red
        allocate-turtles
      ]
    
    end
    
    to allocate-turtles
      if (pcolor = 9.9 and any? turtles-here)
      [
      set size 1.5
      set heading 0                                                                                                                          
      setxy int random-xcor int random-ycor
      ]    
    end
    
    to go
      move-people
      arrive-reception
      arrive-triage
      go-drroom
      tick
    end
    
    to move-people
      ask turtles [
      rt 360
      forward 1
     ]
    end
    
    to arrive-reception
      ask n-of (random count turtles) turtles
      [
      if windows = 1
      [
       move-to patch -2 34
       ifelse not any? turtles-here
       [ wait wait-time ]
       [ wait-in-queue ]
      ]      
      ]
    end
    
     to wait-in-queue
       set arrival-time ticks
      bk 1
      if any? other turtles-here
        [ wait-in-queue ]
      wait wait-time
     if ticks - arrival-time > wait-time
     [ set arrival-time 0
       fd 1 ]
    end
    
    to arrive-triage
     if triage = "Open"
      [
       move-to patch 26 11
       if any? other turtles-here
        [ wait-in-queue]
       wait wait-time
       move-to one-of patches with [pcolor = 109 and not any? other turtles-here ]
       wait wait-time 
       ]   
     end
    
     to go-drroom
       move-to one-of patches with [pcolor = 128]
       if ( min-one-of other turtles in-radius 5 [distance myself] != nobody)
       [
        move-to one-of patches with [pcolor = 129]
       if ( min-one-of other turtles in-radius 5 [distance myself] != nobody)
        [
         move-to one-of patches with [pcolor = 5]
         if any? seats with [turtles = nobody]
           [
             move-to one-of max-n-of 6 neighbors [seats]
           ]
        ]
      ]
      wait wait-time
      die
      end
    

Thanks.

Upvotes: 0

Views: 425

Answers (1)

JenB
JenB

Reputation: 17678

First, some basic programming tricks - don't write so much before trying to debug. If you make a small change and check it, then it's easy to work out where the error is. The first draft of a procedure can be as simple as:

to go-drroom
end

and then fill in the details of what happens in the procedure later.

Typically this error is because you forgot to close a bracket somewhere. That is, one of the procedures starts with ask turtles [ ... and there is no ] so NetLogo is still thinking that the code applies to turtles. However, I can't see an obvious missing ].

But you do have a conceptual problem. The term context is used in NetLogo to refer to who is asking the code to be done and to whom. So ask turtles [ forward 1] is the observer asking the turtles to move and is an observer context procedure. You are not thinking about what context you are in when writing the procedures, and this is probably what is setting off your error.

In the go procedure, you first call move-people. This does ask turtles [ ] so is (appropriately) from the observer context. Then you call arrive-reception and it is also okay.

But then you call arrive-triage and go-drroom still from the observer context and have commands like move-to. Who is being asked to move? You don't have ask turtles .... On the other hand, the procedure wait-in-queue has commands like move-to, but it is fine because it is only called from within an ask turtles ... in the arrive-reception procedure.

Upvotes: 1

Related Questions