This article's documentation is for anything that uses the Source engine. Click here for more information.

Math counter: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (→‎Keyvalues: Initial value is a float but is converted to an integer at run-time, losing fractional values and being rounded off)
(additional info)
 
(15 intermediate revisions by 8 users not shown)
Line 1: Line 1:
{{Entity|math_counter|sprite=1|type=e0}} It stores and manipulates a numerical value. It can trigger on reaching user-defined maximum or minimum values, or output its value every time it changes. It also has the ability to perform simple mathematical functions. When the math_counter is disabled, it will become read-only until re-enabled.
{{TabsBar|main=math_counter}}
 
{{CD|CMathCounter|file1=logicentities.cpp}}
{{code class|CMathCounter|logicentities.cpp}}
{{this is a|logical entity|sprite=1|name=math_counter}} It stores and manipulates a numerical value. It can trigger on reaching user-defined maximum or minimum values, or output its value every time it changes. It also has the ability to perform simple mathematical functions. When the math_counter is disabled, it will become read-only until re-enabled.
 
{{clr}}
 
== See also ==
* [[logic_case]]
* [[math_remap]]
* [[func_movelinear]]


== Keyvalues ==
== Keyvalues ==
{{KV|Initial Value|intn=startvalue|float|Starting value for the counter.}}
{{KV Targetname}}
{{ModernBug|When the entity is created at run-time, this value is converted to an integer and will be rounded off!|offset=1}}
{{KV|Initial Value|intn=startvalue|float|Starting value for the counter. If min or max are set, the starting value is clamped.}}
{{ModernWorkaround|Set the initial value at run-time using the entity's <code>SetValue</code> input. For example, from a {{ent|logic_relay}} using its <code>OnSpawn</code> output.|offset=2}}
:{{bug|hidetested=1|When the entity is spawned, this value is converted to an integer and will be rounded off. {{workaround|Set the initial value at run-time using the entity's <code>SetValue</code> input. For example, from a {{ent|logic_relay}} using its <code>OnSpawn</code> output.}}}}
{{KV|Minimum Legal Value|intn=min|float|Minimum legal value for the counter. If min{{=}}0 and max{{=}}0, no clamping is performed.}}
{{KV|Minimum Legal Value|intn=min|float|Minimum legal value for the counter. If min{{=}}0 and max{{=}}0, no clamping is performed.}}
{{KV|Maximum Legal Value|intn=max|float|Maximum legal value for the counter. If min{{=}}0 and max{{=}}0, no clamping is performed.}}
{{KV|Maximum Legal Value|intn=max|float|Maximum legal value for the counter. If min{{=}}0 and max{{=}}0, no clamping is performed.}}
{{KV Targetname}}
{{KV StartDisabled}}
{{KV EnableDisable}}


== Inputs ==
== Inputs ==
{{IO|Add|Add an amount to the counter and fire the <code>OutValue</code> output with the result.|param=float}}
{{I|Add|Add an amount to the counter and fire the <code>OutValue</code> output with the result.|param=float}}
{{IO|Divide|Divide the counter by an amount and fire the <code>OutValue</code> output with the result.|param=float}}
{{I|Divide|Divide the counter by an amount and fire the <code>OutValue</code> output with the result.|param=float}}
{{note|If this causes a division by zero, the counter will ignore the input.}}
{{note|If this causes a division by zero, the counter will ignore the input.}}
{{IO|Multiply|Multiply the counter by an amount and fire the <code>OutValue</code> output with the result.|param=float}}
{{I|Multiply|Multiply the counter by an amount and fire the <code>OutValue</code> output with the result.|param=float}}
{{IO|SetValue|Set the counter to a new value and fire the <code>OutValue</code> output with the result.|param=float}}
{{I|SetValue|Set the counter to a new value and fire the <code>OutValue</code> output with the result.|param=float}}
{{IO|SetValueNoFire|Set the counter to a new value without firing any outputs.|param=float}}
{{I|SetValueNoFire|Set the counter to a new value without firing any outputs.|param=float}}
{{IO|Subtract|Subtract an amount from the counter and fire the <code>OutValue</code> output with the result.|param=float}}
{{I|Subtract|Subtract an amount from the counter and fire the <code>OutValue</code> output with the result.|param=float}}
{{IO|SetHitMax|Set the upper bound of the counter and fire the <code>OutValue</code> output with the current value.|param=float}}
{{I|SetHitMax|Set the upper bound of the counter and fire the <code>OutValue</code> output with the current value.|param=float}}
{{IO|SetHitMin|Set the lower bound of the counter and fire the <code>OutValue</code> output with the current value.|param=float}}
{{I|SetHitMin|Set the lower bound of the counter and fire the <code>OutValue</code> output with the current value.|param=float}}
{{IO|GetValue|Causes the counter to fire its <code>OnGetValue</code> output with the current value of the counter. Used for polling the counter when you don't want constant updates from the <code>OutValue</code> output.}}
{{I|GetValue|Causes the counter to fire its <code>OnGetValue</code> output with the current value of the counter. Used for polling the counter when you don't want constant updates from the <code>OutValue</code> output.}}
{{IO|SetMaxValueNoFire|Set the counter to the MaxValue without firing any outputs.|param=float|since=P2}}
{{I|SetMaxValueNoFire|Set the counter to the MaxValue without firing any outputs.|param=float|since=p2|also=mapbase}}
{{IO|SetMinValueNoFire|Set the counter to the MinValue without firing any outputs.|param=float|since=P2}}
{{I|SetMinValueNoFire|Set the counter to the MinValue without firing any outputs.|param=float|since=p2|also=mapbase}}
{{I EnableDisable}}
{{I EnableDisable}}


== Outputs ==
== Outputs ==
{{IO|OutValue|Fired when the counter value changes.<br>If the Target Input's parameters is left empty, the math_counter's value is used. {{tip|Useful for entities such as: {{ent|logic_case}},{{ent|math_remap}},{{ent|logic_compare}}.}}|param=float}}
{{O|OutValue| activator = activator of the input that changes the value
{{IO|OnHitMin|Fired when the counter value meets or goes below the min value. The counter must go back above the min value before the output will fire again.}}
|Fired when the counter value changes.<br>If the Target Input's parameters is left empty, the math_counter's value is used. {{tip|Useful for entities such as: {{ent|logic_case}},{{ent|math_remap}},{{ent|logic_compare}}.}}|param=float}}
{{IO|OnHitMax|Fired when the counter value meets or exceeds the max value. The counter must go below the max value before the output will fire again.}}
{{O|OnHitMin| activator = activator of the input that caused this
{{IO|OnGetValue|Fired in response to the <code>GetValue</code> input; used when you don't want constant updates from the <code>OutValue</code> output.<br>If the Target Input's parameters is left empty, the math_counter's value is used. {{tip|Useful for entities such as: {{ent|logic_case}},{{ent|math_remap}},{{ent|logic_compare}}.}} |param=float}}
|Fired when the counter value meets or goes below the min value. The counter must go back above the min value before the output will fire again.}}
{{IO|OnChangedFromMin|Fired when the counter value changes from the minimum value.|since=AS}}
{{O|OnHitMax| activator = activator of the input that caused this
{{IO|OnChangedFromMax|Fired when the counter value changes from the max value.|since=AS}}
|Fired when the counter value meets or exceeds the max value. The counter must go below the max value before the output will fire again.}}
{{O|OnGetValue| activator = activator of GetValue input
| caller = caller of GetValue input
|Fired in response to the <code>GetValue</code> input; used when you don't want constant updates from the <code>OutValue</code> output.<br>If the Target Input's parameters is left empty, the math_counter's value is used. {{tip|Useful for entities such as: {{ent|logic_case}},{{ent|math_remap}},{{ent|logic_compare}}.}} |param=float}}
{{O|OnChangedFromMin| activator = activator of the input that caused this
|Fired when the counter value changes from the minimum value.|since=as|also=mapbase}}
{{O|OnChangedFromMax| activator = activator of the input that caused this
|Fired when the counter value changes from the max value.|since=as|also=mapbase}}
 
== See also ==
* {{ent|logic_case}}
* {{ent|math_remap}}
* {{ent|func_movelinear}}

Latest revision as of 11:04, 16 June 2025

edit
C++ Class hierarchy
CMathCounter
CLogicalEntity
CServerOnlyEntity
CBaseEntity
C++ logicentities.cpp
Math counter.png

math_counter is a logical entity available in all Source Source games. It stores and manipulates a numerical value. It can trigger on reaching user-defined maximum or minimum values, or output its value every time it changes. It also has the ability to perform simple mathematical functions. When the math_counter is disabled, it will become read-only until re-enabled.

Keyvalues

Name (targetname) <string>[ Edit ]
The name that other entities refer to this entity by, via Inputs/Outputs or other keyvalues (e.g. parentname or target).
Also displayed in Hammer's 2D views and Entity Report.
See also:  Generic Keyvalues, Inputs and Outputs available to all entities

Initial Value (startvalue) <float>
Starting value for the counter. If min or max are set, the starting value is clamped.
Icon-Bug.pngBug:When the entity is spawned, this value is converted to an integer and will be rounded off.
PlacementTip.pngWorkaround:Set the initial value at run-time using the entity's SetValue input. For example, from a logic_relay using its OnSpawn output.
Minimum Legal Value (min) <float>
Minimum legal value for the counter. If min=0 and max=0, no clamping is performed.
Maximum Legal Value (max) <float>
Maximum legal value for the counter. If min=0 and max=0, no clamping is performed.
Start Disabled (StartDisabled) <boolean>
Stay dormant until activated (with theEnableinput).

Inputs

Add <floatRedirectInput/float>
Add an amount to the counter and fire the OutValue output with the result.
Divide <floatRedirectInput/float>
Divide the counter by an amount and fire the OutValue output with the result.
Note.pngNote:If this causes a division by zero, the counter will ignore the input.
Multiply <floatRedirectInput/float>
Multiply the counter by an amount and fire the OutValue output with the result.
SetValue <floatRedirectInput/float>
Set the counter to a new value and fire the OutValue output with the result.
SetValueNoFire <floatRedirectInput/float>
Set the counter to a new value without firing any outputs.
Subtract <floatRedirectInput/float>
Subtract an amount from the counter and fire the OutValue output with the result.
SetHitMax <floatRedirectInput/float>
Set the upper bound of the counter and fire the OutValue output with the current value.
SetHitMin <floatRedirectInput/float>
Set the lower bound of the counter and fire the OutValue output with the current value.
GetValue
Causes the counter to fire its OnGetValue output with the current value of the counter. Used for polling the counter when you don't want constant updates from the OutValue output.
SetMaxValueNoFire <floatRedirectInput/float> (in all games since Portal 2) (also in Mapbase)
Set the counter to the MaxValue without firing any outputs.
SetMinValueNoFire <floatRedirectInput/float> (in all games since Portal 2) (also in Mapbase)
Set the counter to the MinValue without firing any outputs.

EnableDisable:

Enable / Disable
Enable/disable this entity from performing its task. It might also disappear from view.

Outputs

OutValue <floatRedirectOutput/float>
!activator = activator of the input that changes the value
!caller = this entity
Fired when the counter value changes.
If the Target Input's parameters is left empty, the math_counter's value is used.
Tip.pngTip:Useful for entities such as: logic_case,math_remap,logic_compare.
OnHitMin
!activator = activator of the input that caused this
!caller = this entity
Fired when the counter value meets or goes below the min value. The counter must go back above the min value before the output will fire again.
OnHitMax
!activator = activator of the input that caused this
!caller = this entity
Fired when the counter value meets or exceeds the max value. The counter must go below the max value before the output will fire again.
OnGetValue <floatRedirectOutput/float>
!activator = activator of GetValue input
!caller = caller of GetValue input
Fired in response to the GetValue input; used when you don't want constant updates from the OutValue output.
If the Target Input's parameters is left empty, the math_counter's value is used.
Tip.pngTip:Useful for entities such as: logic_case,math_remap,logic_compare.
OnChangedFromMin  (in all games since Alien Swarm) (also in Mapbase)
!activator = activator of the input that caused this
!caller = this entity
Fired when the counter value changes from the minimum value.
OnChangedFromMax  (in all games since Alien Swarm) (also in Mapbase)
!activator = activator of the input that caused this
!caller = this entity
Fired when the counter value changes from the max value.

See also