Andrew
Andrew

Reputation: 21

Netlogo using Countdown to temporarily modify agent behaviour

Thank you for reading this, any advice gratefully received :)

I have a switch (a panic button) when turned on all Agents values are changed and a countdown (global var) initiated. When countdown reaches 1 all Agent values are re-set and panic is over.

Problem is that panic is never over!! Via a monitor I can see my countdown is not going 10,9,8 etc (as expected) but 10,-9181,-198187 etc (random number, always negative).

I must be missing something really simple! My procedures (called from go):

to start-panic 

    ask generals
    [ if panic = true and countdown = 10
       [ set fear fear + 1 
         set probability probability + 1
         set canchat? true
         set conversation 10 
         set countdown countdown - 1 ] ]
end

to continue-panic

    ask generals
    [ if panic = true
     [ set countdown countdown - 1 ] ]
end

to stop-panic

    ask generals
    [ if panic = true and countdown = 1
     [ set panic false
       set fear fear - 1
       set probability probability - 1
       set canchat? false
       set conversation 5 
       set countdown 10 ] ]
end

Upvotes: 1

Views: 84

Answers (2)

Andrew
Andrew

Reputation: 21

Thank you Seth. Your reply made me think about contexts.

I discovered i was calling the continue-panic procedure as:

ask turtles [ continue-panic ] 

whereas the correct logic is

if panic [ continue-panic ]

This countdown works fine now, panic is over (both mine and agents)

Upvotes: 1

Seth Tisue
Seth Tisue

Reputation: 30508

You have set countdown countdown - 1 inside ask generals, so every general decrements the countdown. But you only wanted it decremented once.

Taking start-panic for an example, I think you intended logic more like:

to start-panic 
    if panic and countdown = 10 [
      ask generals
       [ set fear fear + 1 
         set probability probability + 1
         set canchat? true
         set conversation 10 ]
      set countdown countdown - 1 ]
end

Upvotes: 0

Related Questions