Assignment is the basis of AVS coding. In the newest version of AVS there is a function, assign( variable , value ), which stores "value" in "variable". This is a function version of the command variable = value;. All this is doing is taking the value on the right hand side of the "equation" and storing it into the variable (it must be a variable, not an expression - I'll get into that in a second) on the left hand side.
The best way to think of this is as an iterative approach. Some people will tell you that "this form of assignment is confusing, because it works backwards." This is simply not true, and can lead to a lot of terrible misunderstandings. This is not only the most common type of assignment, but it is also a lot easier to think about than the 'assembly' form, which is backwards (although in assembly it is done in such a way that it is also easy to deal with mentally).
In an iterative approach, you are simply stating that the variable on the left hand side is an "iteration": a step in the process. Variables in programming are not static values as they are in mathematics. Assignment is a way to change their value - in higher mathematics, you can express it as follows:
z(n+1)=z(n)^2+c (the Julia iteration)
This is saying that the next iteration of "z" is equal to the square of the current iteration plus a constant. The next iteration is not the same thing as the current iteration; while it may be the same value, it is not the same variable. In programming, you are basically doing this, but without the iterative notation (the (n+1) part).
If it's still not making sense, look at it this way: every time you do an assignment, you are changing a variable's value. So a statement like x=x+1 does not state that x equals x+1, but that x+1 is assigned to x; or that the value of x is changed to the value of x+1. x=x+1 means that you are adding 1 to x and then recycling it back into x.
The syntax of an assignment, if you have not already guessed, is a single variable followed by an equals sign followed by a mathematical expression:
variable=expression
The expression can contain functions, variables, and sub-expressions contained by parentheses, all seperated by operators. The variable must follow the rules for bariable names, which I will discuss later. Variables are any strings of letters - "words" - that are not immediately followed by parentheses; strings that are followed by parentheses are functions. For example, red, onbeat, and alpha are all variables; getosc(...) and if(...) are functions. The stuff inside the parentheses after a function's name (getosc and if) is not a single expression, it is one ore more "arguments" that are "passed" to the function. Each argument must be a valid expression, and arguments must be seperated by commas. Operators are any of the following charachters, and define the "interactions" between variables, functions, and subexpressions: + - * / % & |
The first four you are probably familiar with: addition, subtraction, multiplication, and division. The last three are modulus, bitwise AND and bitwise OR. I'll explain those later.
A single assignment is a type of command. In the newest version of AVS, functions can also be used as commands. All commands are seperated my semicolons (;).
Some examples of commands and code pieces:
x = sin(r)*(getosc(i,0,1)+1);
y = cos(r)*(getosc(i,0,2)+1);
red = i*5|0%2;
if( alpha-1, 0 ,exec2(assign(x,0),assign(y,0)));
Don't get in too much of a fuss over seperating everything correctly and putting everything in the right order. All you should really be thinking when you're coding is if the computer could read something in more than one way. In time you won't even have to think about your syntax when you are coding, except for the occasional battle with how many parentheses you are using, or the order of operations. It becomes lowered to mentally saying "if 'alpha minus 1' do 0, otherwise do exec2 x equals 0 then y equals 0," although most people never actually word it out in their head...I hope ;)
To summarize:
-
An expression is a string of operations that contains variables, functions, and sub-expressions contained by parentheses; the variables, functions, and sub-expressions are seperated by operators. Expressions are used after an equals sign in an assignment or as arguments in a function.
-
Variables are strings of charachters that are not directly followed by parentheses.
Functions are strings of charachters that are directly followed by parentheses which contain arguments.
-
Arguments are expressions seperated by commas that are passed to functions.
-
A command is a line that starts with a variable or a function and ends with a semicolon. If it starts with a variable, the variable must be followed by an equals sign, and then by an expression.