Counters

From Battlepedia
Jump to navigationJump to search
Essentials Series
  1. Introduction
  2. Industrial Park Basics
  3. Editing Assets
  4. Templates
  5. Links
  6. Tikis and Enemies

This page is part of the Essential Series modding tutorials. In this guide, you will learn how to use CNTR assets. A counter is an base asset that keeps track of a single number value. A counter's value is able to be modified, accessed, and reset at any time. CNTRs are placed in the Default layer of the HIP file.

Using a Counter

Industrial Park has a Counter template. When placing the template, you can choose the initial value stored in the counter. This value is an integer that can be in the range of -32,768 to 32,767. Counters are used for creating game logic: for example, if you want an event to be sent after pressing three buttons, or after destroying 10 enemies, you can use a counter with its initial value set to 3 or 10, and have each button or enemy asset decrement the counter, until 0 is reached. These are the events used by a counter:

  • Reset: Send this event to a counter to reset its initial value.
  • Expired: This event is sent to the counter when its value reaches 0. Once in 'Expired' mode, Increment and Decrement do not work anymore until you send Reset to it.
  • Increment: Send this to a counter to increase its value by one. If the new value is 0, Expired will be sent as well. If the new value is between 1 and 20, an event between Count1 and Count20 will be sent as well.
  • Decrement: Send this to a counter to decrease its value by one. If the new value is 0, Expired will be sent as well. If the new value is between 1 and 20, an event between Count1 and Count20 will be sent as well.
  • Count1 to Count20: these are twenty different events. Sending one of them to a counter will override its value with the corresponding count. The events are also received by the counter when the new value (set after Increment or Decrement) is between 1 and 20.

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).

An example of using counters in the game is Mr. Krab's Dream (Krabby Patty Platforms). Each robot, on death, sends Decrement to a counter whose initial value is 5. The counters use Count1 to Count5 events to send events to the different Krabby Patty ingredient platforms and make them move.

You can also use a counter to save a binary value (using 0 as false and 1 as true, for example).

Counters are normally reset to their initial value on ScenePrepare (every time a level loads or after player death). To make a counter's value persist between loads, set StateIsPersistent to true. The counter's value will be stored in the save file and remain the same even after turning the game off. More information about this in the Dispatchers tutorial.

Using Conditionals

Conditionals can access a counter's value. More information on the Conditionals page.