Expressions: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(→Logic) |
||
Line 67: | Line 67: | ||
== Functions == | == Functions == | ||
=== Logic === | === Logic === | ||
<syntaxhighlight> | <syntaxhighlight> | ||
Line 73: | Line 72: | ||
?( test expression, if true, if false ) | ?( test expression, if true, if false ) | ||
exists( value ) | exists( value ) | ||
not( value ) | |||
!( value ) | |||
~( value ) | |||
case( test value, default, case1 ) | |||
type( value ) | |||
</syntaxhighlight> | |||
=== Math === | |||
<syntaxhighlight> | |||
min( value 1, value 2 ) | min( value 1, value 2 ) | ||
max( value 1, value 2 ) | max( value 1, value 2 ) | ||
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 ) | ||
sqrt( value ) | sqrt( value ) | ||
pow( base, exponent ) | pow( base, exponent ) | ||
Line 103: | Line 93: | ||
randomint( minimum value, maximum value ) | randomint( minimum value, maximum value ) | ||
randomfloat( minimum value, maximum value ) | randomfloat( minimum value, maximum value ) | ||
int( value ) | |||
float( value ) | |||
sin( angle in radians ) | sin( angle in radians ) | ||
cos( angle in radians ) | cos( angle in radians ) | ||
Line 110: | Line 101: | ||
atan2( x, y ) | atan2( x, y ) | ||
abs( value ) | abs( value ) | ||
</syntaxhighlight> | |||
=== Vector === | |||
<syntaxhighlight> | |||
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 ) | |||
</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 121: | Line 129: | ||
endswith( string, suffix ) | endswith( string, suffix ) | ||
find( haystack, needle ) | find( haystack, needle ) | ||
</syntaxhighlight> | |||
=== Entity === | |||
<syntaxhighlight> | |||
playeratindex( index ) | |||
entityindex( entity ) | |||
playeritematslot( entity, slot ) | |||
attribute( player or item, attribute name ) | |||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 21:50, 4 March 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 " inside expression, but you are allowed to use comma , .
Syntax
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 | 7 > 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 |
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
Functions
Logic
test( test expression, if true, if false )
?( test expression, if true, if false )
exists( value )
not( value )
!( value )
~( value )
case( test value, default, case1 )
type( value )
Math
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
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
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 )
Entity
playeratindex( index )
entityindex( entity )
playeritematslot( entity, slot )
attribute( player or item, attribute name )