120 likes | 216 Views
Game Maker Tutorials 1. Variables and Simple Controls. Content. GML (game maker language) Variables Relative and Not Relative IF statements IF ELSE statements. Variable. What is it? Location in memory with a variable _______ Programs use it to _______ information
E N D
Game Maker Tutorials 1 Variables and Simple Controls
Content • GML (game maker language) • Variables • Relative and Not Relative • IF statements • IF ELSE statements
Variable • What is it? • Location in memory with a variable _______ • Programs use it to _______ information • Why do we need it? • To keep track of things • ________________ • _____________
How to create variable in GM? • In the _________ tab • The square symbol ______ • Click and the screen appears
Creating a variable • Lets create a variable to hold the amount of keys we have • We need to give it a name, But lets make it global E.g. global.keys We set the value to say… 6 • Now we have create a location in memory named “keys” and stored 6 in it. • _______________________ • _____ just means it is accessible by all objects in the game.
How do we increment instead? • We tick the Relative box With “Relative” meansadd 6 to the original This is an ______ This is an _________ _______________ ______________________
If Statement • Used to make decisions • e.g. Lets look at some code global.keys = 6 //increment or set? If global.keys > 0 //variable check { global.keys = global.keys – 1 //decrement } To do a if statement you use _________ symbols Since we want to check a variable we use
How to do in GM? If global.keys > 0 { global.keys = global.keys – 1 }
Setting up your IF statement If global.keys > 0 = equals > < >= <= less than and equal
IF statement global.keys = 0 ; //_______________ If global.keys > 0 //______________ { global.keys = global.keys – 1 ; //____________ } • What will happen now?
IF Else Statement global.keys= 0 //set to zero if global.keys > 0 //variable check { global.keys = global.keys – 1; //decrement } else { draw_text(x,y, “you got no keys); } • ___________________________________
Having MORE Else Test element: global.keys if global.keys < 0 // below but not equal to { draw_text(x,y, 'no keys'); } else if global.keys =1 //checks a single number { draw_text(x,y, 'happy'); } else if global.keys >= 3 and global.keys < 6 //handles a range { draw_text(x,y, 'coolness'); } else if global.keys >= 7 //greater and equal to { draw_text(x,y, 'awesomeness'); } else { draw_text(x,y, 'joy'); }