08.11.2012 Views

Designing Games with Game Maker - YoYo Games

Designing Games with Game Maker - YoYo Games

Designing Games with Game Maker - YoYo Games

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

}<br />

instance_create(xx,yy,ball);<br />

Addressing variables in other instances<br />

As described earlier, you can set variables in the current instance using statements like<br />

x = 3;<br />

But in a number of cases you want to address variables in another instance. For example, you<br />

might want to stop the motion of all balls, or you might want to move the main character to a<br />

particular position, or, in the case of a collision, you might want to set the sprite for the other<br />

instance involved. This can be achieved by preceding the variable name <strong>with</strong> the name of an<br />

object and a dot. So for example, you can write<br />

ball.speed = 0;<br />

This will change the speed of all instances of object ball. There are a number of special<br />

"objects".<br />

• self: The current instance for which we are executing the action<br />

• other: The other instance involved in a collision event<br />

• all: All instances<br />

• noone: No instance at all (sounds weird probably but it does come in handy as we will<br />

see later on)<br />

• global: Not an instance at all, but a container that stores global variables<br />

So, for example, you can use the following kind of statements:<br />

other.sprite_index = sprite5;<br />

all.speed = 0;<br />

global.message = 'A good result';<br />

global.x = ball.x;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!