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 />

}<br />

repeat (5) instance_create(random(400),random(400),ball);<br />

While statement<br />

A while statement has the form<br />

while () <br />

As long as the expression is true, the statement (which can also be a block) is executed. Be<br />

careful <strong>with</strong> your while loops. You can easily make them loop forever, in which case your game<br />

will hang and not react to any user input anymore.<br />

Example<br />

The following program tries to place the current object at a free position (this is about the<br />

same as the action to move an object to a random position).<br />

{<br />

}<br />

while (!place_free(x,y))<br />

{<br />

}<br />

Do statement<br />

x = random(room_width);<br />

y = random(room_height);<br />

A do statement has the form<br />

do until()<br />

The statement (which can also be a block) is executed until the expression is true. The<br />

statement is executed at least once. Be careful <strong>with</strong> your do loops. You can easily make them<br />

loop forever, in which case your game will hang and not react to any user input anymore.

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

Saved successfully!

Ooh no, something went wrong!