GM: Actions

From GMpedia.org Wiki

Jump to: navigation, search

Contents

[edit] The Game Maker actions

[edit] Introduction

[edit] X and Y

First of all, I will explain the X and the Y axis. Although most people with an average knowledge in mathematics would easily know what that means, I decided to explain the X and Y axis, for those who do not have an idea about them. The X and Y set the position of the object, and the picture on the right will explain everything to you.

[edit] "Applies to..."

Second, I will explain an important part of Game Maker, the "Apply To:" section in the action window. This is where you choose to what object you must apply this action:

  • to the object itself (selected by default)
  • to the other object (only work in collision event)
  • to a specific object (specified with a drop-down menu)

[edit] The actions

[edit] Start moving in a direction

This action will make the object start moving in a particular direction in a certain speed. Click on the direction you want the object to go to, and define the speed. The button in the center makes the object stand still. If you click on two different buttons, the object will randomly choose one position to go to.

[edit] Set the direction and speed of motion

Very obvious; this action will set/change the direction and speed of the motion of the object.

[edit] Move in the direction of a point

This action will let the object move to the direction of a certain point defined by you. The object will move in a speed defined by the programmer as well.

[edit] Set the horizontal speed

This action sets the horizontal speed of the object. Setting it to 0 will result no horizontal movement. Setting it to 1+ will result moving to the right. And setting it to -1- will result moving to the left.

[edit] Set the vertical speed

This action sets the vertical speed of the object. Setting it to 0 will result no vertical movement. Setting it to 1+ will result movement towards the bottom. And setting it to -1- will result moving upwards.

[edit] Set the gravity

This action sets the gravity power and its direction. The gravity power is how much the object is towards the direction of the gravity. Setting the gravity direction to 0 means its direction is to the right, setting to 90 means that its direction is upwards, setting it to 180 moves it to the left and that means that setting it to 270 will move it downwards.

[edit] Reverse horizontal direction

This will reverse the horizontal direction of the object. If the horizontal direction was to the left, it becomes to the right.

[edit] Reverse vertical direction

This will reverse the vertical direction of the object. If the object direction was upwards, it becomes downwards. Using "Reverse horizontal direction" and "Reverse vertical direction" together will make the object reverse its direction completely, and form a reaction movement.

[edit] Set the friction

This will set the power of the friction affecting an object in every step (millisecond). Forget all about the math! The friction in Game Maker is very simple, if the friction of an object is ".1" the speed (horizontal and vertical) is reduced by ".1" until the speed reaches 0. Note that if the speed was negative, ".1" will be added to it.

[edit] Jump to a given position

This action will change the position of the object instantly to a new position set by the x and the y.

[edit] Jump to the start position

This action will change the position of the object instantly to its start position. You need to set nothing; the object will automatically move the position where it was first created.

[edit] Jump to a random position

The object will jump to a random direction. But you still have to set the Horizontal Snap and the Vertical Snap.

[edit] Snap to a grid

This will move the object to the nearest grid line. The width and height of the grid is defined by the user. For those of you who do not know what a grid is, a grid is sort of a net, which objects can be aligned to.

[edit] Move to a contact position

The help file explain this easily: With this action you can move the instance in a given direction until a contact position with an object is reached. If there already is a collision at the current position the instance is not moved. Otherwise, the instance is placed just before a collision occurs. You can specify the direction but also a maximal distance to move.

[edit] Bounce against objects

This will make an object bounce (react) against objects. There are two things you have to set:

  1. Whether or not the bouncing is precise: If you set Precise to false, the object will react against horizontal or vertical walls properly only. If you set Precise to true, the object will react against all objects properly.
  2. Bouncing against solid objects only or all objects?

We recommend this action to be put in the collision event.

[edit] Create an instance of an object

This action will create a certain object in a certain position defined by the programmer.

[edit] Create an instance of an object with a motion

This action will create a certain object in a certain position, but that object will be created with motion. That means you have to set the speed and direction of the newly created object. Direction is 0-360, 0: Right, 90: Up, 180: Left, 270: Down.

[edit] Change the instance

This action will turn the object into another object. You need to set the object and whether or not to perform destroy event for the old object and the create event for the new object.

[edit] Destroy the instance

This action will destroy the object.

[edit] Destroy instances at position

This will destroy all instances (objects) located in a certain position defined by the programmer.

[edit] Change the sprite

This will change the object's sprite (or the sprite that represents the object). You must set the sprite, the sub image (-1 for all), and the image speed (1=normal).

[edit] Transform the sprite

This action will transform the shape of the sprite. You must change the "xscale" and this is the amount of scaling for the sprite's width. If the "xscale" is 1, the sprite's width will not change its size. Then you must set the "yscale". Then the image angle (rotation). If the image angle was 0, the sprite will not be rotated. Finally, you will be asked to choose the mirror, whether you want the sprite to have no mirroring, mirror horizontal, vertical, or both. Below, there is a table describing the x and y scales.

  • Less than -1
The sprite will be mirrored/flipped but with a bigger width/height.
  • -1
The sprite will be mirrored/flipped but with the same width/height.
  • 0 -> -1
The sprite will be mirrored/flipped but with a smaller width/height.
  • 0
The sprite will be invisible.
  • 0 -> 1
The sprite will get shrunk horizontally/vertically.
  • 1
The sprite will have the same size.
  • More than 1
The sprite will grow horizontally/vertically.

[edit] Set sprite blending

This will set the color/alpha blending of the object's sprite. The blending is what color the object should fade to. White is the normal blending for an object. The image alpha is the transparency of the object. If the alpha was 1 the object will be visible. If the alpha was 0 the object will be invisible. If it was .5 the object will be semitransparent.

[edit] Play a sound

This action will either play a sound once, or loop a sound.

[edit] Stop a sound

This action will either stop a sound that didn't finish playing, or will stop a looping sound.

[edit] Set an alarm

This action sets a particular alarm to certain amount of milliseconds. To learn more about alarm events see the previous documentation.

[edit] Sleep for a while

This action will stop the game for a certain number of milliseconds. You must check whether or not to redraw the screen. We recommend setting the redraw to true.

[edit] Set a timeline

This action will set a time line. The position is from when the timeline will start. If you select 0, the time line will start from the beginning.

[edit] Set timeline position

This action will set the position of a certain timeline. The position of the time line is discussed previously.

[edit] Display a message

This action will display a message.

[edit] Show the game info

This action will show the game information. The game information is where you write the game help and other remarks.

[edit] Show a video

This action will show a video in the game.

[edit] Restart the game

This action will restart the game.

[edit] End the game

This action will end/quit the game.

[edit] Save the game

This action will save all the game changes into a specific file set by the programmer.

[edit] Load the game

This action will load all the game changes saved from a previous save from a specific file set by the programmer.

[edit] Replace a sprite from a file

This action will change a sprite. The replacement of the sprite will be imported from a file. You must set the sprite to be changed, and the name of the file (.gif/.bmp). And then you must enter the number of images (sub images actually) that the user must replace (1 for a still image).

[edit] Replace a sound from a file

This action will replace a sound from file.

[edit] Replace a background from a file

This action will replace a background from file.

[edit] Call the inherited event

This is a somehow complex action that will be understood later on.

[edit] Call a script

This action will execute a script with all its arguments.

[edit] Put some comment

This action is no action. It will just put some comments so you can organize your thoughts. A comment in Drag & Drop actions is equivalent to a phrase surrounded by /* and */ or one line of code that has // in the beginning (the text in a // comment must occupy one line only).

[edit] Introduction to If Conditions and blocks

Till now, you may think that you can make a professional game, but the truth is its hard to do that now. You need more complex condition checking. So the game will make one thing if an expression is true. These are the If Statements (and sometimes called the If Conditions). If you want to perform one action if an expression is true, you will place the action after the If condition action. You can do that using an “If Statement” in the same way as below:

If Condition – If something is true, a variable equal to a value for example (see below for info about variables). Action – if the statement above is true, this action is performed.

However, if you want to perform many actions if a certain expression is true, it will not be easy to repeat the same If condition multiple times for such a result. Instead you can place the "Start of block" and "End of block" actions. And you can simple make multiple actions:

If Condition
Start of block
Action
Action
Action
End of block

This way you can make much professional games with Game Maker. However, what will you do if you want the action to perform something if an expression is true, and something else if the expression isn't true? There are two ways, either repeating the same if condition with the "Not" checkbox checked, and this will evaluate the exact opposite of the expression. But the better action to use is the "Else" action, where it actually works like the If Condition but MUST be placed after the If condition is ended. That is either after the end of block of the If Condition, or after the action as indicated in the first example.

If Condition
Start of block
Action
Action
Action
Action
End of block
Else
Start of block
Action
Action
End of block

[edit] If a sound is playing

Is an If condition that checks whether a certain sound is playing or not.

[edit] If previous room exists

This action is an If Conditions that checks whether or not the previous room exists.

[edit] If next room exists

This action is an If Conditions that checks whether or not the next room exists.

[edit] If a position is collision free

An If Condition that checks whether or not a certain position contains any object in it. (It performs the action if the position doesn't contain objects).

[edit] If there is a collision at position

An If Condition that checks whether or not a certain position collides with any object. (Perform actions if it does).

[edit] If there is an object at position

An If Condition that checks whether or not a certain object is located in a certain position.

[edit] If the number of instances is a value

An If Condition that check the number of certain objects in the room. If the number of the instances was equal to the number defined by the user, actions will be performed.

[edit] With a chance perform the next action

This action performs an action with a chance of certain sides.

[edit] If the user answers yes to a question

This If Condition will display a message asking a "Yes/No" question. If the player chooses yes, the actions for the If Statement will be performed.

[edit] If an expression is true

This is an If Condition that checks whether a certain statement is true or not. Learning more about statements is required before using this action properly.

[edit] If a mouse button is pressed

If a mouse button is pressed, an action will be performed.

[edit] If an instance is aligned with a grid

This will perform an action if a certain instance is aligned (snapped) to grid.

[edit] Exit this event

This action will stop the execution of the event.

[edit] Loops

[edit] Repeat next action

This action will repeat the next action a number of times defined by the user. You can use blocks in this action.

[edit] Introduction to variables

Variables are values that can change. Like "fast", fast is a variable, fast can be 0, 1, 2, 3, or anything at all. While the number "5" is only 5! A variable name can be anything, but it must not contain:

.	!	@	#	$
%	^	&	*	(
)	-	=	+	\
<	>	/	?	<space>
{	}	[	]	,
|	`	~	"	'

To make it easier, a variable name can only contain letters and numbers and underscores (_). It can begin with letters, and underscores, but it cannot begin with numbers.

Setting a variable is easy, you either use the drag and drop action, that is simple enough or use this form of code:

//setting a variable to 1
variable=1;

Variables in Game Maker are either "real" or "strings".

[edit] Real

Real values for variables are numbers. 1, 2, 3, or 10000 are all real values. When setting the value you simply enter the value.

[edit] String

Strings are great types of values to variables. "Hello" can be a string "123 ABC" is a string. A string is any kind of text surrounded by quotations ("s) or ('s). When setting a variable's value to string, you surround the value with quotations marks.

[edit] Variables: Global & Local

Variables are even cooler! Suppose you have two objects, one object's variable (happy) is set to 1, the other object's variable happy is set to 0. This way every object has its own happy. But what if you want all objects to have the same value? This way you can use global variables. The first object is the object that initializes everything, it asks the player for yes/no questions and sets variables. For example:

If the user answers yes to a question: "Are you happy"
Start of a block
Set a variable: happy to 1
End of a block
Else
Start of a block
Set a variable: happy to 0
End of a block

This way initializing object will recognize the variable "stupid" but other objects wont. This is when you use: global. variables. The (.) located between global and the variable name separates the type of variable from the variable name. If it had no (.) in the first place, it will be considered a local variable. Here is an explanation for global variables:

[edit] Global Variables

Global variables are the variables that are not limited on certain objects or rooms. The global variable always exists. If you set global.stupid in room0 by object0, object1 in the same room and object2 in room1 are able to recognize global.stupid.

[edit] Local Variables

Local variables are the variables for the same object.

[edit] All variables

All variables (all.whatever) set a variable for all objects in the room.

[edit] Variable Actions

[edit] Set a variable

This will set a certain variable to certain value.

[edit] If a variable has a value

If a certain variable has a certain value, the If Condition will be executed.

[edit] Draw the value of a variable

This will draw a value of a certain variable in the room (write the value of the variable in the room).

[edit] Set the score

This will set the score.

[edit] If score has a value

If the score has a certain value, actions will be performed.

[edit] Draw the value of the score

This action type is explained before.

[edit] Show the high score table

This action will show the high score.

[edit] Clear the high score table

This action will clear the high score.

[edit] Set the number of lives

This action will set the number of lives to the player.

[edit] If lives has a value

An “If statement” that will see if lives have a certain value.

[edit] Draw the number of lives

This action will draw the number of lives.

[edit] Draw the lives as an image

This action will draw a number of sprites defined by the player next to each other to represent the number of lives.

[edit] Set the health

This action will set the health.

[edit] If health is a value

This action is an “If Statement” that will check the value of the health.

[edit] Draw the health bar

This action will draw a health bar.

[edit] Set the window caption info

This action will set the info to be viewed in the caption (title) of a window.

[edit] MCI Actions

[edit] Play a CD

This action will play a CD.

[edit] Stop the CD

This action will stop the CD from playing.

[edit] Pause the CD

This action will only pause the CD from playing.

[edit] Resume the CD

This action will continue playing the CD after it has been paused.

[edit] If a CD exists in the drive

If there is no CD in the drive.

[edit] If the CD is playing

If the CD is being played.

[edit] Extra actions

Set the mouse cursor This action will set the look of the cursor from a sprite. And you will set if you want to view the original cursor too or not.

[edit] Open a webpage in a browser

This action will open your default web browser, and open a certain page in it.

[edit] Draw Actions

[edit] Draw a sprite

This action will let the object draw a particular sprite with a particular sub image (-1 draws all animating) in a certain position.

[edit] Draw a background image

This action will draw a particular background in a particular position.

[edit] Draw a text

This action will draw (write) text in a certain position.

[edit] Draw text transformed

This action will draw (write) text in a certain position. But with certain x and y scaling (xscale and yscale discussed before), and a certain rotation (angle) that is also discussed before.

[edit] Draw a rectangle

This action will draw a rectangle. Here is what you must insert: x1: The x position where the rectangle will start. y1: The y position where the rectangle will start. x2: The x position where the bottom right part of the rectangle will end. y2: The y position where the bottom right part of the rectangle will end. Filled: If set to true, the rectangle will not be hollow.

[edit] Draw a horizontal gradient, Draw a vertical gradient

This action draws a rectangle with nice effects.

[edit] Draw an ellipse

Draw an oval with the same arguments as a rectangle.

[edit] Draw a gradient ellipse

This action draws an ellipse with nice effects.

[edit] Draw a line

This action will draw a line going from x1,y1 to x2,y2. ====Draw an arrow This action will draw an arrow going from x1,y1 to x2,y2, and you must set the size of the tip of the arrow.

[edit] Set the color

This action will set the color of the drawing.

[edit] Set the font

This will set the font of text drawing to be used and the horizontal aligning for the text.

[edit] Change full screen mode

This action will either change to full screen. Or change to normal view. Or toggle between both.

[edit] Take a snapshot of the image

This will make a screenshot of the window and save it to a particular file.

[edit] Path Actions

[edit] Set path for the instance

This will make an object start a path.

[edit] End the path for an instance

This will make an object end a path.

[edit] Set the position on the path

This will make an object set a position of a path.

[edit] Set the speed for the path

This will make an object set the speed of the path.

[edit] Motion Actions

[edit] Perform a step towards a point

This will make an object move towards a point.

[edit] Step towards a point avoiding objects

This will make an object move towards a point avoiding objects. Either to avoid all objects, or solid objects.

[edit] See Also

Personal tools