home | et13 - game prototyping in Gamemaker prev | next

David Javelosa
javelosa_david@smc.edu

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

 

week 11 - Video, Repurposing, Scripting & Randomization

Running video in Gamemaker: (see full version)


HOW TO REPURPOSE? / Gamemaker Basics Review - Chapter Five: What makes a good game?!!

            What To Change

            - sprites

            - Backgrounds

            - Sounds


            What To Keep

            - objects

            - events/actions

            - rooms


Scripting

Comparing the programming interfaces of then vs. now:

            - Command Line Interface (CLI) - C, C++, Assembler, Basic, DOS, Lingo

            - Graphic User Interface (GUI) - Macintosh, Windows, mouse & menus



GML: The Game Maker Language

Overview:

There are almost 1,000 functions and variables available to control game action in Gamemaker. There are different places where scripts can be inserted. First, a script must first be defined. Secondly, the code action must be added to an event. The code action also must be scripted.Thirdly, scripts can run from a room's creation code. Also, GML expressions can be used when specifying a value in an action. When using GML, all resources must be named with the legal naming convention: start with a letter, no spaces and no punctuation marks except underscore "_". Every resource must have an unique name! Keywords may not be used, including: "self", "other", "global" or "all".

 

A program :

A program is a set of instructions called statements. Each begins with the symbol "{" and is puntuated with a "}".

 

Variables:

Variables are memory locations that store information. They are named for access and can be stored as a real number or a character string. They should be as descriptive as possible such as mouse_x which would indicate horizontal position of the mouse. Legal characters apply. Maximum length for a string is 64. When a new variable is local to an instance, programs in other instances are independent of them.

 

New variables are created when you assign a value to them. They can be local or global.
If you are using several variables in a program, they can be declared at the same time with:

 

var <varname1>, <varname2>, <varname3>,...

 

Assignments:

An assignment stores a value in a variable: <variable> = <expression>

 

Expressions:

An expression can be a simple value or more complicated like a formula suxh as "mouse_x = mouse_x + 10"


Example:

- Create a new Sprite.

- Create a new Object and assign the sprite to it.

- Add a Create event to start a random movement to the object. (Don't forget speed!)

- Add a Mouse left click event to add interactivity to the objects movement.

- Create a new script called "movement" and insert the below statements:


{
if (x < 0 && hspeed < 0) x = room_width + sprite_xoffset;
if (x > room_width && hspeed > 0) x = -sprite_width + sprite_xoffset;
if (y < 0 && vspeed < 0) y = room_height + sprite_yoffset;
if (y > room_height && vspeed > 0) y = -sprite_height + sprite_yoffset;
}

- Add an Other/Outside event to the object with a Script action; assign the "movement" script.

- Create a Room and place the Object in it. Run the game.

When the instance moves outside the room, this script wraps it to the other side of the room.

(note: this is similar to the action "wrap when moving outside" but handles both directions at once.)

Scripts or "code" can also be embedded directly into an object as a "code" action; or called up as a script resource.


Simple Expressions:

//this is a comment


// this randomizes the sprite of an object

{
sprite_index = random(4)
}

If statments

if (<expression>) <statement>

// this tests a condition expressed as an expression and then executes a command as a statement.


TRY OUT DIFFERENT COMBINATIONS! Experiment!



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