EvilEngine/CNTR: Difference between revisions

m
Seil moved page Counter to EvilEngine/CNTR without leaving a redirect
Battlepedia>Seil
m (Seil moved page Counter to EvilEngine/CNTR without leaving a redirect)
 
(13 intermediate revisions by 3 users not shown)
Line 1:
<onlyinclude>
{{#vardefine:typeid|CNTR}}<nowiki/>
{{#vardefine:name|Counter}}<nowiki/>
{{#vardefine:type|[[Base]]}}<nowiki/>
{{#vardefine:basetype|0x16}}<nowiki/>
{{#vardefine:games|Scooby BFBB TSSM Incredibles ROTU RatProto}}<nowiki/>
{{#vardefine:sourcecode|[https://github.com/bfbbdecomp/bfbb/blob/master/src/Core/x/xCounter.h xCounter.h]}}<nowiki/>
{{#vardefine:image|}}<nowiki/>
</onlyinclude>
{{AutoAssetInfobox}}
 
A '''counter''' is a [[Base|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|Increment]], [[#Decrement|Decrement]], and [[#Count1 - Count20|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|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|Expired]] event can be used to detect when a counter reaches 0.
* The [[#Count1 - Count20|Count1 - Count20]] events can be used to detect when a counter gets set to a value between 1 and 20.
* [[COND|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 [[COND#True|True]] and [[COND#False|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|Increment]] or [[#Decrement|Decrement]] is 0 (i.e. incrementing a counter whose value is -1 or decrementing a counter whose value is 1).
 
==Format==
Counters are [[Object Asset|object assets]], so they start with their 0x8 byte header, then are followed by:
 
{| class="wikitable"
! Offset !! Type !! Variable !! Description
|-
| 0x08 || short || '''Countcount''' -|| The initial value of the counter.
|-
| 0x0A || short(2 bytes) || '''Unknown''' - Always|| 0.(padding)
|-
! colspan="34" | Events
|-
| 0xC || Event[numberOfEvents] || '''[[Events]]''' ||
|}
 
==Events==
===Reset===
Sending this event to a counter resets its value back to its initial value. It also turns off its "expired" state (see [[#Expired|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|Expired]]).
 
If its new value is 0, it sends [[#Expired|Expired]] to itself. If its new value is between 1 and 20, it sends a matching [[#Count1 - Count20|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|Expired]]).
 
If its new value is 0, it sends [[#Expired|Expired]] to itself. If its new value is between 1 and 20, it sends a matching [[#Count1 - Count20|Count1 - Count20]] event to itself.
 
===Expired===
This event is sent from a counter to itself when [[#Increment|Increment]] or [[#Decrement|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|Increment]], [[#Decrement|Decrement]], and [[#Count1 - Count20|Count1 - Count20]] events, until it is reset with the [[#Reset|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|Expired]]). For example, sending Count5 to a counter sets its value to 5.
 
If a counter's resulting value from a [[#Increment|Increment]] or [[#Decrement|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|Increment]] is sent to it, it will send Count10 to itself.
 
{{Assets}}
{{AutoGameNavs}}
 
[[Category:Asset]]