home | et13 - game prototyping in Gamemaker prev | next

David Javelosa

Copyright © 2001-2020, David Javelosa unless otherwise stated.


week 12 - More Scripting Examples

This tutorial will show you how to make a simple design maker routine using Game Maker Language to enhance your programs. The loop or repeat command allows for a continuation of actions progressing toward a particular state; such as maximum number of instances.

Create a red ball sprite. Name it sprBall
Create a ball object objBall, and attach the sprite.

Create an empty room, and place the ball exactly in the middle of it. (You can check the coordinates at the bottom of the screen - if the game area is 640x480, the centre is at 320, 240

Add an event to the ball object for when the A key is pressed.

From the control tab, choose

If the number of instances is a value

Put objBall < 3000
(We don't want to create any more balls if there are already more than 3000 on the play area.)

From the control tab, choose

Execute a piece of code

counter=0 //initialize the counter

//this loop will produce 10 balls at a time at 36 degree intervals around the circle


//increment the counter by 36

//create a new ball

//give it a direction

//give it a speed


When the balls leave the play area, we want them to wrap to the other side:

Add an event for when the ball is outside the room (From Other events )

Choose the Wrap around the play area action (in both directions) from the Move tab.

Try varying the code so that a different number of balls are given out each time.

Try varying the degree intervals to change the pattern.

Modify the behavior with a collision event that randomly changes direction!

Try reducing the maximum amount of balls from 3000 to 1000; 500; 100.

Add a mouse event that destroys instance when it enters.

Modify the outside event to destroy instance instead of wrapping.

What event can be used to spawn more balls? When does the loop "run away" and freeze the program?!

You will need to look carefully at the code to work out what you need to change.

original code by Margaret Meijers; margaret.meijers@education.tas.gov.au.


Using the sprite randomization from last week, try randomizing sound playback:


Create 5 sound resources; naming them 0, 1, 2, 3, 4

Using a mouse left pressed event, select the control action execute a piece of code and enter:




This should playback the different sound resources at random.

Try different combinations with interactive or automatically generated events. Be carefull not to generate actions that overload the system's abillity to perform.

Copyright © 2001-2014, David Javelosa unless otherwise stated.