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

Incrementvar: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(How to use it.)
m (Replacing {{console command}}. This operation was performed by a bot.)
 
(12 intermediate revisions by 7 users not shown)
Line 1: Line 1:
A [[console command]] which can increment a given console variable.
{{this is a|console command|name=incrementvar}}
<code>'''incrementvar'''</code> is a [[console command]] which can increment a given console variable. In tandem with {{ent|setinfo}}, it can be used to count things arbitrarily.


==Usage==
==Syntax==
* <code>incrementvar ''varname'' ''minValue'' ''maxValue'' ''delta''</code>
{{pre|incrementvar CVAR MINVALUE MAXVALUE DELTA}}
** Increments the given variable by the ''delta'', whilst keeping the value within the bounds specified by ''minValue'' and ''maxValue''
*<tt>CVAR</tt>: a console variable we want to change.
*<tt>MINVALUE</tt>: a minimum bound for our variable.
*<tt>MAXVALUE</tt>: a maximum bound for our variable.
*<tt>DELTA</tt>: the amount to increase <tt>CVAR</tt> by. Set this to a negative number to ''decrement''.


There is a bug (or at least a wierd way of doing things), where incrementing a variable past the maxValue specified can set it to 0. The example linked below avoids this problem by first decrementing, then incrementing the specified variable.
{{note|Incrementing a variable past the <tt>MAXVALUE</tt> specified causes the variable to loop around to the <tt>MINVALUE</tt>. The same happens the other way around, too.}}


See [Unlocking_chapters_in_your_mod] for an example of how to use incrementvar.
==See also==
*{{ent|toggle}}
*{{ent|multvar}}, multiply var.

Latest revision as of 17:55, 7 January 2024

incrementvar is a console command available in all Source Source games. incrementvar is a console command which can increment a given console variable. In tandem with setinfo, it can be used to count things arbitrarily.

Syntax

incrementvar CVAR MINVALUE MAXVALUE DELTA
  • CVAR: a console variable we want to change.
  • MINVALUE: a minimum bound for our variable.
  • MAXVALUE: a maximum bound for our variable.
  • DELTA: the amount to increase CVAR by. Set this to a negative number to decrement.
Note.pngNote:Incrementing a variable past the MAXVALUE specified causes the variable to loop around to the MINVALUE. The same happens the other way around, too.

See also