Wire Expression2:Differences to Expression1

From GMod Wiki

Jump to: navigation, search

This should either be put back in the main page or extended. If extended it might be a good idea to turn this into a conversion guide.

Introduction

The documentation for Expression Gate 1 very much applies to Expression 2, the only major difference between the languages are if-statements, which you can see below. Except for that, Expression 2 is basically superior in every way, and the basics are exactly the same, it also has a proper code editor!

Firstly we have the lines for variables, which is similar to the Expression Gate, but not quite. The variables in the expression must be declared before you can use them in the expression, so before it would look like:

N@variable example
I@A
O@B
A==1 -> C=!C;
B=(C==1 ? 2 : 1)

and after:

@name variable example
@inputs A
@outputs B
@persist C
if (A==1) {C=!C}
B=(C==1 ? 2 : 1)

You may notice the extra line @persist, which is a line for all variables not defined in inputs or outputs that need to retain their value. Outputs automatically persist. The reason that persistent variables now have to be defined this way, is because there are different types of variables. In Expression Gate, there were only numbers and packets, but there are many other types in Expression 2, like strings, vectors and more and specifying persistent variables allows typos and similar mistakes to be caught by the compiler instead of being treated as zero.

Cases in which persisting is needed: When using delta ($), when using an unassigned variable, when using +=.

New Features

@name vector example
@inputs A:vector
@outputs B:vector
C = vec(0,0,0)
if(A>C) {
    B = A:normalized() * 4
} else {
    B = C + A
}

See Also

Expression Gate 1 documentation

Personal tools