Level 07 Lesson 01 [Using Scripts/Methods]

This lesson is about using scripts/methods. Methods are named chunks of code that might perform a task, send you back some values, or both. You can use methods that have been written by other programmers and you can use methods that you have written. Methods can save you coding time, make your code easier to read, and help you organize your code. GameMaker has many methods that have already been written for you to use so lets take a look at some examples.
Part A – Introduction to Methods
Watch the video: 07-01-A

Challenge 1– Find, Use, and Test
Use the project 07-01-X1Start.

Add extra key press events into the player object and try out using some of the following methods. Read about the methods in the help file to find out more about them.

a) when the player presses ‘R’ use the random method to generate a number and show it with a message.
b) when the player presses ‘M’ use the motion_add method and see what happens.
c) when the player presses ‘E’ use the position_empty method and check if x=112, y=208 is empty or not (it has a hamburger so it shouldn’t be!) . If it is empty, show a message saying empty.
d) when the player presses the ‘D’ key, use the point_direction method to find out the direction toward the upper left corner ( x=0, y=0 ). Once you know this direction, fire an arrow toward this direction.
e) when the player presses the ‘C’ key, use the point_in_circle method to see if the player is within a 100 pixel radius circle that is positioned in the center of the room. The room is 800X600 so the center of the room is at (400,300). If the player is at the center of the room, make their points go up by 1000.

Challenge 1 Solution
Solution Video: 07-01-X1
Solution File: 07-01-X1Done.gmk