<?xml version="1.0" encoding="utf-8"?>
<model version="NetLogo 7.0.4" snapToGrid="true">
  <code><![CDATA[to setup ;; observer procedure
  clear-all
  reset-ticks
end

;; variant 1: clear ticks and reset ticks in same step
to go-v1 ;; observer procedure
  carefully [
    print ticks
  ] [
    print "no ticks"
  ]
  ifelse random-float 100 < prob-clear [
    clear-ticks
    print "stop and restart"
    reset-ticks
  ] [
    carefully [
      tick
    ] [
      ;; skip
    ]
  ]
end

;; variant 2: clear ticks and don't reset ticks
to go-v2 ;; observer procedure
  carefully [
    print ticks
  ] [
    print "no ticks"
  ]
  ifelse random-float 100 < prob-clear [
    clear-ticks
    print "stop"
  ] [
    carefully [
      tick
    ] [
      ;; skip
    ]
  ]
end

;; variant 3: clear ticks and reset ticks in next step
to go-v3 ;; observer procedure
  carefully [
    print ticks
  ] [
    print "no ticks"
  ]
  ifelse random-float 100 < prob-clear [
    clear-ticks
    print "stop"
  ] [
    carefully [
      tick
    ] [
      reset-ticks
    ]
  ]
end]]></code>
  <widgets>
    <view x="210" wrappingAllowedX="true" y="10" frameRate="30.0" minPycor="-10" height="277" showTickCounter="true" patchSize="13.0" fontSize="10" wrappingAllowedY="true" width="277" tickCounterLabel="ticks" maxPycor="10" updateMode="0" maxPxcor="10" minPxcor="-10"></view>
    <button x="20" y="20" height="40" disableUntilTicks="false" forever="false" kind="Observer" width="75">setup</button>
    <slider x="20" step="1" y="72" max="50" width="175" display="prob-clear" height="50" min="1" direction="Horizontal" default="10.0" variable="prob-clear" units="%"></slider>
    <button x="20" y="134" height="40" disableUntilTicks="true" forever="true" kind="Observer" width="75">go-v1</button>
    <button x="120" y="134" height="40" disableUntilTicks="false" forever="true" kind="Observer" width="75">go-v1</button>
    <button x="20" y="186" height="40" disableUntilTicks="true" forever="true" kind="Observer" width="75">go-v2</button>
    <button x="120" y="186" height="40" disableUntilTicks="false" forever="true" kind="Observer" width="75">go-v2</button>
    <button x="20" y="238" height="40" disableUntilTicks="true" forever="true" kind="Observer" width="75">go-v3</button>
    <button x="120" y="238" height="40" disableUntilTicks="false" forever="true" kind="Observer" width="75">go-v3</button>
  </widgets>
  <info>## WHAT IS IT?

The purpose of this model is to investigate what happens to _forever_ buttons when the tick counter is cleared.

There are different variants of combinations of starting and clearing the tick counter.

## HOW IT WORKS

Each step will first print the value of the tick counter or "no ticks" if not started.
Then, in each step there is a probability that the tick counter will be cleared.
For restarting the tick counter or not there are different variants.

1. One variant will restart the tick counter immediately; we expect the _forever_ button will not notice that the tick counter has temporarily stopped.
2. Another variant will not restart the tick counter except for **setup** (a separate button); it is not clear whether this should stop the _forever_ button.
3. The most interesting variant restarts the tick counter in the next step; what would happen?

## HOW TO USE IT

Press button **reset** to start the tick counter, and hence enable the button that are grayed out until the tick counter starts.

All **go** buttons are _forever_ buttons.
There are three variants **go-v1**, **go-v2**, and **go-v3**, for each of the cases described above.
Each **go** variant occurs twice, in the left hand column grayed out initially and in the right hand column always available.

Slider **prob-clear** defines the probability (in percents) that the tick counter is cleared in one step of respective **go** buttons.

## THINGS TO NOTICE

We expect that _forever_ buttons in the right hand column (never grayed out) will not stop automatically in any case.
Buttons in the left hand column (grayed out initially) might or might not stop automatically at some moment. When stopped, we expect the buttons for **go-v2** and **go-v3** to be grayed out again.

## THINGS TO TRY

What happens if we click a running _forever_ button when it stops the tick counter as well?

## NETLOGO FEATURES

Buttons grayed out initially have their attribute "disable until ticks start" set.

The code uses `carefully` to prevent stopping on any errors.

## CREDITS AND REFERENCES

This is just a test model for testing one feature. It was created by Mark R. Kramer.
It is free for use and modification by anyone.</info>
  <turtleShapes>
    <shape name="default" rotatable="true" editableColorIndex="0">
      <polygon color="-1920102913" filled="true" marked="true">
        <point x="150" y="5"></point>
        <point x="40" y="250"></point>
        <point x="150" y="205"></point>
        <point x="260" y="250"></point>
      </polygon>
    </shape>
  </turtleShapes>
  <linkShapes>
    <shape name="default" curviness="0.0">
      <lines>
        <line x="-0.2" visible="false">
          <dash value="0.0"></dash>
          <dash value="1.0"></dash>
        </line>
        <line x="0.0" visible="true">
          <dash value="1.0"></dash>
          <dash value="0.0"></dash>
        </line>
        <line x="0.2" visible="false">
          <dash value="0.0"></dash>
          <dash value="1.0"></dash>
        </line>
      </lines>
      <indicator>
        <shape name="link direction" rotatable="true" editableColorIndex="0">
          <line endX="90" startY="150" marked="true" color="-1920102913" endY="180" startX="150"></line>
          <line endX="210" startY="150" marked="true" color="-1920102913" endY="180" startX="150"></line>
        </shape>
      </indicator>
    </shape>
  </linkShapes>
  <previewCommands>setup repeat 75 [ go ]</previewCommands>
</model>
