SFM/Expression Operator

From Valve Developer Community
< SFM
Revision as of 11:30, 5 September 2014 by Yandros3000 (talk | contribs) (Functions)

Jump to: navigation, search

DmeExpressionOperator

DmeExpressionOperator is a DmeOperator that writes to its "value" float attribute the evaluated expression stored in its "expr" string attribute. The expression can read other float attributes on the DmeExpressionOperator, and can nest arbitrarily deep. For example, the expression "clamp(distance * cos(angle), 0, 10)" will cause the DmeExpressionOperator to write a value between 0 and 10 into its "value" attribute, depending upon the value of its "distance" and "angle" float attributes.

Operator Precedence

  • unary operators: + - ! func var
  • * / %
  • + -
  • < > <= >=
  • == !=
  • &&
  • ||
  •  ?:

Functions

  • dtor(d) : converts degrees to radians
  • rtod(r) : converts radians to degrees
  • abs(a)  : absolute value
  • floor(a)  : rounds down to the nearest integer
  • ceiling(a) : rounds up to the nearest integer
  • round(a)  : rounds to the nearest integer
  • sgn(a)  : if a < 0 returns -1 else 1
  • sqr(a)  : returns a * a
  • sqrt(a)  : returns sqrt(a)
  • sin(a)  : sin(a), a is in degrees
  • asin(a)  : asin(a) returns degrees
  • cos(a)  : cos(a), a is in degrees
  • acos(a)  : acos(a) returns degrees
  • tan(a)  : tan(a), a is in degrees
  • exp(a)  : returns the exponential function of a
  • log(a)  : returns the natural logarithm of a
  • min(a,b)  : if a < b returns a else b
  • max(a,b)  : if a > b returns a else b
  • atan2(a,b) : atan(a/b) returns degrees (it's Arg(b+ia) actually)
  • pow(a,b) : function returns a raised to the power of b
  • inrange(x,a,b) : if x is between a and b, returns 1 else returns 0
  • clamp(x,a,b)  : if x < a returns a else if x > b returns b else returns x
  • ramp(value,a,b)  : returns 0 -> 1 as value goes from a to b
  • lerp(factor,a,b)  : returns a -> b as factor goes from 0 to 1
  • cramp(value,a,b)  : clamp(ramp(value,a,b),0,1)
  • clerp(factor,a,b)  : clamp(lerp(factor,a,b),a,b)
  • elerp(x,a,b)  : ramp( 3*x*x - 2*x*x*x, a, b)
  • noise(a,b,c) : { solid noise pattern (improved perlin noise) indexed with three numbers }
  • rescale (X,Xa,Xb,Ya,Yb) : lerp(ramp(X,Xa,Xb),Ya,Yb)
  • crescale(X,Xa,Xb,Ya,Yb) : clamp(rescale(X,Xa,Xb,Ya,Yb),Ya,Yb)