EvilEngine/CNTR

A counter is a base asset that keeps track of a single number value. This value is an integer that can be in the range of -32,768 to 32,767. A counter's value is able to be modified, accessed, and reset at any time.

A counter can be in two (currently known) states: normal (0) and expired (1). When a counter is in normal state, its value can be freely modified with the Increment, Decrement, and Count1 - Count20 events. If a counter's value is ever set to 0, it becomes expired. When a counter is expired its value cannot be modified by any events until you send the Reset event to it, which resets its state back to normal and its value back to the value initially set in the counter asset.

A counter's current value can be accessed a few different ways.
 * The Expired event can be used to detect when a counter reaches 0.
 * The Count1 - Count20 events can be used to detect when a counter gets set to a value between 1 and 20.
 * Conditionals also have the ability to check the current value of any counter in the scene. This lets you check against any value (not just 0-20) and gives you more options for how to set up your counter. For example, if you only want to store a Boolean value in a counter, you can use a conditional to translate the counter's 0-1 value into a True and False event.

The most common use of a counter is to make something happen after something else happens a specific amount of times. For example, you can earn a spatula in Squidward's house by jumping up and down 10 times. There is a counter whose initial value is 10 and gets decremented every time you jump (a trigger detects when you are slightly above the ground). When the counter reaches 0 (expires), you get the spatula. (There are several events that go into you actually getting the spatula, but it doesn't need to be explained here.)

Note that setting a counter's initial value to 0 does not make it expired. It only becomes expired when its new value after receiving Increment or Decrement is 0 (i.e. incrementing a counter whose value is -1 or decrementing a counter whose value is 1).

Format
Counters are object assets, so they start with their 0x8 byte header, then are followed by:

Reset
Sending this event to a counter resets its value back to its initial value. It also turns off its "expired" state (see Expired), so that its value is able to be changed.

Increment
Sending this event to a counter adds 1 to its current value, unless the counter is expired (see Expired).

If its new value is 0, it sends Expired to itself. If its new value is between 1 and 20, it sends a matching Count1 - Count20 event to itself.

Decrement
Sending this event to a counter subtracts 1 from its current value, unless the counter is expired (see Expired).

If its new value is 0, it sends Expired to itself. If its new value is between 1 and 20, it sends a matching Count1 - Count20 event to itself.

Expired
This event is sent from a counter to itself when Increment or Decrement sets its value to 0.

Sending this event to a counter sets its value to 0. It also turns on its "expired" state, which prevents its value from being changed by the Increment, Decrement, and Count1 - Count20 events, until it is reset with the Reset event.

Count1 - Count20
There are 20 events named Count1, Count2, Count3, etc. all the way through Count20.

Sending one of these events to a counter sets its value to the number in the name of the event, unless the counter is expired (see Expired). For example, sending Count5 to a counter sets its value to 5.

If a counter's resulting value from a Increment or Decrement event is between 1 and 20, a Count event with the number matching the new value is sent from the counter to itself. For example, if a counter's value is 9 and Increment is sent to it, it will send Count10 to itself.