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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

do<br />

{<br />

}<br />

x = random(room_width);<br />

y = random(room_height);<br />

until (place_free(x,y))<br />

For statement<br />

A for statement has the form<br />

for ( ; ;)<br />

<br />

This works as follows. First statement1 is executed. Then the expression is evaluated. If it is<br />

true, statement 3 is executed; then statement 2 and then the expression is evaluated again.<br />

This continues until the expression is false.<br />

This may sound complicated. You should interpret this as follows. The first statement initializes<br />

the for-loop. The expression tests whether the loop should be ended. Statement2 is the step<br />

statement that goes to the next loop evaluation.<br />

The most common use is to have a counter run through some range.<br />

Example<br />

The following program initializes an array of length 10 <strong>with</strong> the values 1- 10.<br />

{

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

Saved successfully!

Ooh no, something went wrong!