Login | Register

Operators

August 25, 2006, 21:11 by Calle
[loading]
-->
As listed in the manual that comes with Game Maker, the operators are these:
• && || ^^: combine Boolean values (&& = and, || = or, ^^ = xor)
• < <= == != > >=: comparisons, result in true (1) or false (0)
• | & ^: bitwise operators (| = bitwise or, & = bitwise and, ^ = bitwise xor)
• << >>: bitwise operators (<< = shift left, > > = shift right)
• + -: addition, subtraction
• * / div mod: multiplication, division, integer division, and modulo
They are binary. There also exists a few unary operators, here listed with their effect:
• !: not, turns true into false and false into true
• -: negates the next value
• ~: negates the next value bitwise
The binary operators will be highly useful for us later on when we begin to construct conditions, in the meantime we will only use them for some different assignments:

“ready = false; //ready is false, which is equal to zero
ready = !ready; //ready is turned into true, which equals one
ready = -ready //turns one, which is true, into minus one”

I bet the last thing, = -ready felt quite natural. You can easily see why it makes a negative value out of the positive one. Harder is it though, to understand why 0 becomes 1. That is nothing you need to bother your mind with though, just remember it because it might be very useful later on.

Two binary operators are mod and div. I sometimes doubt their usefulness and I rarely use them myself, but it might be good to know how to use them, therefore I’ll explain. Div is a short for divide, I suppose, and it does divide but also rounds. So x div y is the same as round(x/y) … mod is short for modulo, x mod y is the same thing as x - (x div y) * y

One assignment could therefore med this:
image_single = direction mod 10;

Comments

Loading comments... [loading]
.
Users logged in:

game maker articles, game maker examples, game maker tutorials, gmtutorials, game maker questions and answers, game maker crash course, how to create games