Editing Expressions

Jump to navigation Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
You can use expressions as input parameter to reduce the amount of logic entities used. Expressions in input parameter start with $$=
For example, using this as input parameter: $$='Health: ('..!activator.m_iHealth..'/'..!activator.m_iMaxHealth..')' will set health information as input parameter.
Expressions are calculated during input execution.
Do not put double quote (i.e. " ) inside expression, but you are allowed to use commas (i.e. , ).
As an admin, sig_expression "expression" command in console can be used to test expressions. (i.e: sig_expression "2+2" echoes Result: 4)
== Syntax ==
{| class="wikitable"
|+
!
!
!Example
|-
|'AADSD'
|literal string
|'AADSD'
|-
|4.3
|number
|4.3
|-
|[1 4 5.5]
|vector
|[1 4 5.5]
|-
|entityname.variable
|access entity [https://raw.githubusercontent.com/powerlord/tf2-data/master/netprops.txt sendprop], [https://raw.githubusercontent.com/powerlord/tf2-data/master/datamaps.txt datamap], or custom variable
|!activator.m_iHealth + 41
|-
| + - * / %
|add, subtract, multiply, divide, modulo operators
|5 + 2
|-
|..
|join strings
|'This is ' .. 2 .. ' awesome'
|-
|> >= < <= == !=
|comparison operators
|test(7 > 3, 1, 3)
|-
|()
|parentheses, expression inside is calculated before others
|(4 + 3) * 2
|-
|function(param 1, param 2 ...)
|function
|min(entity.m_iHealth, entity2.m_iHealth)
|-
|<nowiki>&& ||</nowiki>
|and, or operators
|entity.m_iHealth > 4 && entity2.m_iHealth < 2
|-
|<nowiki>& | ^</nowiki>
|and, or, xor binary operators
|
|-
|>> <<
|right bit shift, left bit shift
|
|-
|pi
|pi number
|pi * pi
|-
|degtorad, radtodeg
|convert angle between degrees and radiants
|9 * degtorad
|-
|true, false
|logical true/false
|
|}
Values are automatically converted when types of left and right sides of operators differ.
For example, [1 4 5] + 4 will automatically convert 4 to [4 4 4] vector.
\' escapes single quotes inside literal string.
== Functions ==
== Functions ==
=== Logic ===
<syntaxhighlight>
<syntaxhighlight>
test( test expression, if true, if false )
test( test expression, if true, if false )
?( test expression, if true, if false )
?( test expression, if true, if false )
- Tests an expression for true or false, then returns a specified value based on that.
exists( value )
exists( value )
- Checks whether a value exists, then returns true or false. [Needs verification]
not( value )
!( value )
~( value )
- Inverts a value - f.e. from false to true. [Needs verification]
case( test value, default, case1, [case2] ... )
- Tests a value, and compares it to a list of cases; returns a case number. [Needs verification]
type( value )
- Returns the type of the value: string, int, etc. [Needs verification]
</syntaxhighlight>
=== Entity ===
<syntaxhighlight lang="c">
playeratindex( index )
entityindex( entity )
playeritematslot( entity, slot )
attribute( player or item, 'attribute name' ) // attribute name must be in single quotes
</syntaxhighlight>
=== Math ===
<syntaxhighlight>
min( value 1, value 2 )
min( value 1, value 2 )
max( value 1, value 2 )
max( value 1, value 2 )
length( vector )
distance( vector 1, vector 2 )
dotproduct( vector 1, vector 2 )
crossproduct( vector 1, vector 2 )
rotate( input vector, rotation angles )
normalize( vector )
toangles( vector )
toforwardvector( vector )
clamp( input value, minimum value, maximum value )
clamp( input value, minimum value, maximum value )
remap( input value, from min, from max, to min, to max )
remap( input value, from min, from max, to min, to max )
remapclamped( input value, from min, from max, to min, to max )
remapclamped( input value, from min, from max, to min, to max )
int( value )
float( value )
string( value )
stringpad( value, min digits, num digits after decimal point )
vector( string or X coordinate )
x( vector )
y( vector )
z( vector )
not( value )
!( value )
~( value )
sqrt( value )
sqrt( value )
pow( base, exponent )
pow( base, exponent )
Line 126: Line 34:
randomint( minimum value, maximum value )
randomint( minimum value, maximum value )
randomfloat( minimum value, maximum value )
randomfloat( minimum value, maximum value )
int( value )
case( test value, default, case1 )
float( value )
sin( angle in radians )
sin( angle in radians )
cos( angle in radians )
cos( angle in radians )
Line 134: Line 41:
atan2( x, y )
atan2( x, y )
abs( value )
abs( value )
</syntaxhighlight>
playeratindex( index )
 
entityindex( entity )
=== Vector ===
playeritematslot( entity, slot )
<syntaxhighlight>
attribute( player or item, attribute name )
length( vector )
type( value )
distance( vector 1, vector 2 )
dotproduct( vector 1, vector 2 )
crossproduct( vector 1, vector 2 )
rotate( input vector, rotation angles )
normalize( vector )
toangles( vector )
toforwardvector( angles )
vector( string or X coordinate, [Y coordinate], [Z coordinate] )
x( vector )
y( vector )
z( vector )
</syntaxhighlight>
 
=== Strings ===
<syntaxhighlight>
string( value )
stringpad( value, min digits, num digits after decimal point )
charat( string, pos )
charat( string, pos )
substr( string, pos, length )
substr( string, pos, length )
Line 163: Line 53:
find( haystack, needle )
find( haystack, needle )
</syntaxhighlight>
</syntaxhighlight>
[[Category:Misc Additions]]
Please note that all contributions to SigMod are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see SigMod:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)