Expressions: Difference between revisions

From SigMod
Jump to navigation Jump to search
(Added temporary notes to the Logic section, based on my personal knowledge. Would be good to have these all verified with their exact details.)
 
(6 intermediate revisions by 2 users not shown)
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 $$=
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
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 .
Expressions are calculated during input execution.


Do not put double quote " inside expression, but you are allowed to use comma , .
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 ==
== Syntax ==
Line 27: Line 29:
|-
|-
|entityname.variable
|entityname.variable
|access entity sendprop, datamap, or custom 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
|!activator.m_iHealth + 41
|-
|-
Line 40: Line 42:
|> >= < <= == !=
|> >= < <= == !=
|comparison operators
|comparison operators
|7 > 3
|test(7 > 3, 1, 3)
|-
|-
|()
|()
Line 76: Line 78:
Values are automatically converted when types of left and right sides of operators differ.
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
For example, [1 4 5] + 4 will automatically convert 4 to [4 4 4] vector.


\' escapes single quotes inside literal string
\' escapes single quotes inside literal string.


== Functions ==
== Functions ==
Line 85: Line 87:
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 )
not( value )
!( value )
!( value )
~( value )
~( value )
case( test value, default, case1 )
- 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 )
type( value )
- Returns the type of the value: string, int, etc. [Needs verification]
</syntaxhighlight>
</syntaxhighlight>


=== Entity ===
=== Entity ===
<syntaxhighlight>
<syntaxhighlight lang="c">
playeratindex( index )
playeratindex( index )
entityindex( entity )
entityindex( entity )
playeritematslot( entity, slot )
playeritematslot( entity, slot )
attribute( player or item, attribute name )
attribute( player or item, 'attribute name' ) // attribute name must be in single quotes
</syntaxhighlight>
</syntaxhighlight>


Line 152: Line 163:
find( haystack, needle )
find( haystack, needle )
</syntaxhighlight>
</syntaxhighlight>
[[Category:Misc Additions]]

Latest revision as of 12:11, 22 July 2022

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[edit | edit source]

Example
'AADSD' literal string 'AADSD'
4.3 number 4.3
[1 4 5.5] vector [1 4 5.5]
entityname.variable access entity sendprop, 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)
&& || and, or operators entity.m_iHealth > 4 && entity2.m_iHealth < 2
& | ^ 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[edit | edit source]

Logic[edit | edit source]

test( 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 )
- 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]

Entity[edit | edit source]

playeratindex( index )
entityindex( entity )
playeritematslot( entity, slot )
attribute( player or item, 'attribute name' ) // attribute name must be in single quotes

Math[edit | edit source]

min( value 1, value 2 )
max( value 1, value 2 )
clamp( input value, minimum value, maximum value )
remap( input value, from min, from max, to min, to max )
remapclamped( input value, from min, from max, to min, to max )
sqrt( value )
pow( base, exponent )
floor( value )
ceil( value )
randomint( minimum value, maximum value )
randomfloat( minimum value, maximum value )
int( value )
float( value )
sin( angle in radians )
cos( angle in radians )
tan( angle in radians )
atan( value )
atan2( x, y )
abs( value )

Vector[edit | edit source]

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( angles )
vector( string or X coordinate, [Y coordinate], [Z coordinate] ) 
x( vector )
y( vector )
z( vector )

Strings[edit | edit source]

string( value )
stringpad( value, min digits, num digits after decimal point )
charat( string, pos )
substr( string, pos, length )
substring( string, pos, length )
startswith( string, prefix )
endswith( string, suffix )
find( haystack, needle )