Math counter: Difference between revisions
		
		
		
		
		
		Jump to navigation
		Jump to search
		
				
		

Note:If this causes a division by zero, the counter will ignore the input.
		
	
 (false bug)  | 
				 (Making this wording consistent with SetHitMax and SetHitMin, after I lost an hour to a bug caused by assuming it set the counter's value to its current max value)  | 
				||
| (6 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
{{TabsBar|main=math_counter}}  | {{TabsBar|main=math_counter}}  | ||
{{CD|CMathCounter|file1=logicentities.cpp}}  | {{CD|CMathCounter|file1=logicentities.cpp}}  | ||
{{this is a|  | {{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.  | ||
== Keyvalues ==  | == Keyvalues ==  | ||
| Line 9: | Line 9: | ||
{{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   | {{KV StartDisabled}}  | ||
== Inputs ==  | == Inputs ==  | ||
| Line 22: | Line 22: | ||
{{I|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}}  | ||
{{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.}}  | {{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.}}  | ||
{{I|SetMaxValueNoFire|Set the counter   | {{I|SetMaxValueNoFire|Set the upper bound of the counter without firing any outputs.|param=float|since=p2|also=mapbase}}  | ||
{{I|SetMinValueNoFire|Set the counter   | {{I|SetMinValueNoFire|Set the lower bound of the counter without firing any outputs.|param=float|since=p2|also=mapbase}}  | ||
{{I EnableDisable}}  | {{I EnableDisable}}  | ||
== Outputs ==  | == Outputs ==  | ||
{{O|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  | ||
{{O|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}}  | ||
{{O|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  | ||
{{O|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.}}  | ||
{{O|OnChangedFromMin|Fired when the counter value changes from the minimum value.|since=  | {{O|OnHitMax| activator = activator of the input that caused this  | ||
{{O|OnChangedFromMax|Fired when the counter value changes from the max value.|since=  | |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 ==  | == See also ==  | ||
Latest revision as of 21:12, 1 October 2025
| CMathCounter | 

math_counter  is a   logical entity  available in all 
 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. 
parentnameortarget).
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.
 
Bug: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 SetValueinput. For example, from a logic_relay using itsOnSpawnoutput.
- 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 the
Enableinput). 
Inputs
- Add <float>
 - Add an amount to the counter and fire the 
OutValueoutput with the result. 
- Divide <float>
 - Divide the counter by an amount and fire the 
OutValueoutput with the result. 
- Multiply <float>
 - Multiply the counter by an amount and fire the 
OutValueoutput with the result. 
- SetValue <float>
 - Set the counter to a new value and fire the 
OutValueoutput with the result. 
- SetValueNoFire <float>
 - Set the counter to a new value without firing any outputs.
 
- Subtract <float>
 - Subtract an amount from the counter and fire the 
OutValueoutput with the result. 
- SetHitMax <float>
 - Set the upper bound of the counter and fire the 
OutValueoutput with the current value. 
- SetHitMin <float>
 - Set the lower bound of the counter and fire the 
OutValueoutput with the current value. 
- GetValue
 - Causes the counter to fire its 
OnGetValueoutput with the current value of the counter. Used for polling the counter when you don't want constant updates from theOutValueoutput. 
- SetMaxValueNoFire  <float> (in all games since 
) (also in 
) - Set the upper bound of the counter without firing any outputs.
 
- SetMinValueNoFire  <float> (in all games since 
) (also in 
) - Set the lower bound of the counter without firing any outputs.
 
EnableDisable:
- Enable / Disable
 - Enable/disable this entity from performing its task. It might also disappear from view.
 
Outputs
- OutValue <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: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 <float>
 - !activator = activator of GetValue input
!caller = caller of GetValue input
Fired in response to theGetValueinput; used when you don't want constant updates from theOutValueoutput.
If the Target Input's parameters is left empty, the math_counter's value is used.
Tip:Useful for entities such as: logic_case,math_remap,logic_compare. 
- OnChangedFromMin   (in all games since 
) (also in 
) - !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 
) (also in 
) - !activator = activator of the input that caused this
!caller = this entity
Fired when the counter value changes from the max value.