2. GML Interpreted programming language that you can use to substantially enhance the games you create using Game Maker Supplement Extend Replace Actions Interpreted Programming Language Scripts are interpreted and compiled just before they are executed
3. Game Maker Scripts Menu Import Scripts Export Scripts Show Built-In Variables – Global/local variables Show Built-In Functions – Game Maker’s functions Show Extension functions – through extension pkgs Show Constants Show Resource Names – resources defined in your app Search in Scripts – matching strings Check Resource Names – look for resource name conflicts Check All Scripts – syntax check
4. Game Maker Scripts Editor Accessed through the Script Properties Window Create scripts by typing the window Auto color-coded Assists in writing code Smart tabs automatically indent statements
5. Syntax Scripts are made up of one ore more GML code statements embedded within an opening bracket and closing bracket { } All code statements should end with a semi-colon ;
6. Adding a script {//set the drawing colordraw_set_color(c_black);//draw a filled rectangledraw_rectangle(50,50,590,430,false);//set the drawing colordraw_set_color(c_yellow);//draw textdraw_text(210,200,"Hello World");} Then assign an object to execute a script May also be created as code if only used once
7. Executing GML Code to Rooms Can execute code when rooms are created Open a room and click on its settings tab Button at the bottom of the tab labeled Creation Code Code for the room will be executed once (and only once) when the room is created
8. GML Scripting Data types Integer – any whole number positive or negative, as well as 0 Real – Numbers that include decimal points String – Set of characters embedded within single or double quotations
9. Variables Variable – pointer to a location in memory where data is stored Variable names must begin with a letter Letters, numbers, underscores No blanks No game maker language key words or names of defined resources To assign a value to a variable, use the “=“ Name = “Tracy”;
10. Special Variables X – coordinate for a given object y – “ “ Direction Speed Hspeed Vspeed Solid Sprite_height Sprite_width
11. Constants A constant is a value whose value is known at design time and does not change during the execution of the game Colors, for example (c_black, c_blue, c_green) Click on “show constants” on the scripts menu Constants cannot be “accidentally” changed, are self-documenting, and typically require less memory
12. Arrays An array is an indexed list of data that is stored and managed as a collection, preserving the value of the variable and its relationship with other variables One dimensional and two dimensional Arrayname[indices] Ex: {names[0]=“Captain Jack”;names[1]=“Mad Hatter”;names[2]=“Willy Wonka”;}
13. Setting up a Loop Set up a loop For(i=0; I<3; i=i+1) {draw_text(x,y,names[i]); y = y+20} Executes the script three times Can be used to list each item in an array
14. The IF statement The if statement is used to evaluate an expression and then initate an action if that expression evaluates as true. If (expression){ statements;} Example (if statement as part of a guessing game:if(secretnumber=real(userGuess)) show_message(“You Guessed It”); If statements can be nested