Difference between revisions of "Math counter"

From Valve Developer Community
Jump to: navigation, search
(Counters use and input/output floating point values, not integers.)
m (This should also be a float too.)
 
Line 23: Line 23:
 
{{IO|Multiply|Multiply the counter by an amount and fire the <code>OutValue</code> output with the result.|param=float}}
 
{{IO|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}}
 
{{IO|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=integer}}
+
{{IO|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}}
 
{{IO|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}}
 
{{IO|SetHitMax|Set the upper bound of the counter and fire the <code>OutValue</code> output with the current value.|param=float}}

Latest revision as of 08:11, 12 September 2018

Math counter.png
math_counter is a point 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.

In code, it is represented by class CMathCounter, defined in logicentities.cpp.

See also

Keyvalues

Initial Value (startvalue) <float>
Starting value for the counter.
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.

Targetname:

Name <string>
The targetname that other entities refer to this entity by.
Entity Scripts <scriptlist> (New with Left 4 Dead 2)
Space delimited list of VScript files (without file extension) that are executed after all entities have spawned. The scripts are all executed in the same script scope, later ones overwriting any identical variables and functions.
Script think function <string> (New with Left 4 Dead 2)
Name of a function in this entity's script which will be called automatically every 100 milliseconds (ten times a second) for the duration of the script. It can be used to create timers or to simulate autonomous behavior. The return value (if present) will set the time until the next call.
Note:Try to avoid expensive operations in this function, as it may cause performance problems.

EnableDisable:

Start Disabled (StartDisabled) <boolean>
Stay dormant until activated (probably with the Enable input).

Inputs

Add  <float>
Add an amount to the counter and fire the OutValue output with the result.
Divide  <float>
Divide the counter by an amount and fire the OutValue output with the result.
Note:If this causes a division by zero, the counter will ignore the input.
Multiply  <float>
Multiply the counter by an amount and fire the OutValue output with the result.
SetValue  <float>
Set the counter to a new value and fire the OutValue output 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 OutValue output with the result.
SetHitMax  <float>
Set the upper bound of the counter and fire the OutValue output with the current value.
SetHitMin  <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  <float> (New with Portal 2)
Set the counter to the MaxValue without firing any outputs.
SetMinValueNoFire  <float> (New with Portal 2)
Set the counter to the MinValue without firing any outputs.

Targetname:

Kill
Removes this entity and any entities parented to it from the world.
KillHierarchy
Functions the same as Kill, although this entity and any entities parented to it are killed on the same frame, being marginally faster than Kill.
AddOutput  <string>
Evaluates a keyvalue/output on this entity. It can be potentially very dangerous, use with care.
Format: <key> <value>
Format: <output name> <targetname>:<inputname>:<parameter>:<delay>:<max times to fire, -1 means infinite>
FireUser1 to FireUser4
Fire the OnUser outputs; see User Inputs and Outputs.
Use  !FGD
Same as a player invoking +use; may not do anything. Can also be invoked by creating an output that does not specify an input.
This input is not included in Valve's FGDs.
RunScriptFile  <script> (New with Left 4 Dead 2)
Execute a VScript file from disk, without file extension. The script contents are merged with the script scope of the receiving entity.
RunScriptCode  <string> (New with Left 4 Dead 2)
Execute a string of VScript source code in the scope of the entity receiving the input. String quotation may be needed when fired via console.
Bug: In <Left 4 Dead 2>, the code is executed in the script scope of the entity that fires the output, not the one receiving the input.
Warning: Never try to pass string parameters to a script function with this input. It will corrupt the VMF structure because of the nested quotation marks, which then must be removed manually with a text editor.
CallScriptFunction  <string> (New with Left 4 Dead 2) !FGD
Execute a VScript function in the scope of the receiving entity.
SetLocalOrigin  <coordinates> (New with Alien Swarm) !FGD
Send this entity to a spot in the map. If the entity is parented to something, it will be offset from the parent by this amount.
SetLocalAngles  <angles> (New with Alien Swarm) !FGD
Set this entity's angles.

EnableDisable:

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

Outputs

OutValue  <float>
Fired when the counter value changes.
Note:Generates the value of the math_counter into the parameters section of an Output Statement. To use a generated parameter, just leave the field reading <none>.
Tip:Useful in tandem with logic_case and logic_compare
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.
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.
OnGetValue  <float>
Fired in response to the GetValue input. Used for polling the counter when you don't want constant updates from the OutValue output.
Note:Generates the value of the math_counter into the parameters section of an Output Statement. To use a generated parameter, just leave the field reading <none>.
Tip:Useful in tandem with logic_case, math_remap and logic_compare.
OnChangedFromMin  (New with Alien Swarm)
Fired when the counter value changes from the minimum value.
OnChangedFromMax  (New with Alien Swarm)
Fired when the counter value changes from the max value.

Targetname:

OnUser1 to OnUser4
These Outputs each fire in response to the firing of the like-numbered FireUser1 to FireUser4 Input; see User Inputs and Outputs.
OnKilled  (Only in the Left 4 Dead series)
This Output fires when the entity is killed and removed from the game.