Objects, Functions and Parameters Susan Ibach | Technical Evangelist Sage Franch | Microsoft Student Partner
Mastering a few key concepts will allow you to understand your code! Objects Functions Parameters Properties
Objects
An object is a representation of something in a game or app Set lives in the game to 1. noun object Examples of objects we use in code include A button A character in our game The game itself Grammar is different depending on language.
What objects do we have in our game? obstacle hero board game
Functions
A function is an action associated with an object Set lives in the game to 1. verb function Functions allows us to Manipulate the object (make it bigger, smaller, faster) Create new objects (add text or a picture to the board) Perform an action (start a timer, end the game, remove a life) Grammar is different depending on language.
Different objects have different functions Functions on the game object: Functions on the hero object: This is only a few of the functions!
Objects and Functions in our game
What are those symbols? Indicates the function being called for this object Indicates that this is a “special” object, with LOTS of functions.
Parameters
A parameter is a value passed to a function Set lives in the game to 1. parameter Parameters allow you to control what a function will do How big to make an object How fast to make an object move How many points to score Grammar is different depending on language.
Not all functions accept parameters Sometimes functions just perform a specific action and you don’t need to provide extra information Some functions don’t take parameters. Some of what you see here are “properties” on objects. Properties will come later.
Some functions return an object Some functions, like set life(), just do something Like change the number of lives in a game But some functions, return something… This function returns an object. We are storing the returned object in a variable called board. (Board can have its own functions and properties!)
Think of functions that return objects as vending machines…
Or…
Properties
Properties give us information about our objects How big is our hero? width or height How many lives does the game have left? life How fast is our hero moving? speed
We can change the value of a property by calling a function and passing in a parameter Change the size of our hero set width(100) or set height(100) Change the number of lives in our game set life(3) Change the speed of our hero set speed(400)
Resize our hero & Change number of lives in the game
Your challenge Resize your hero Set number of lives in your game to a value of your choosing
Congratulations! You can speak code.
Vocabulary and concepts Object: A self-contained entity that includes both functions and data (properties). An object in code is like a noun in a sentence. Function: A procedure or routine that does a specific task. A function in code is like a verb in a sentence. Some functions just do something, but some return an object Parameter: A value (or variable) that is passed to a function. Property: An attribute of an object A property is like an adjective in a sentence