Functions
Functions Methods that return a Value Number Boolean (True/False) Object Other (Sound, Video, etc.) Does not change the current state of the world Does not move / change objects
What Functions Do Check a current condition (run-time) Get information about objects Where they are Size Ask questions about the state of the world As it is now With program running
Built In Functions Proximity Size Spatial Relationship Point of View Relation to other objects Size Spatial Relationship Point of View Proximity – where the object is Distance to Distance to right/left/above/below/behind Size: Height Width Depth Smaller Than/Larger Than Spatial Relationship To the left of To the right of above / below in front of / behind Point of View: Point of View Position
Where to Use – Calling the Function Anywhere that requires the type of information returned from the function Number Object Boolean Example: Bopper.move (how far) Bopper.move (distanceTo(mole))
Create Your Own Function Exercise 6-1 #2 Create a new world with a car or truck. Write a program to make the 4 wheels of the car realistically turn forward as the car moves forward. Why a function??? Roll and move forward at the same time doesn’t look realistic. When cars move the tires do not rotate at the same rate as the car is moving forward Rotation must be based on the size of the tires (distance / (3.14 * diameter))
Create Your Own Function Like Creating a Method Select Object in Object Tree Select Functions from Details Window Create New Function
Create Your Own Function Name Type Return Type Must have a Return Type Number Boolean Object Other
Coding Function Code Function Cannot Delete the Return Statement All functions return some Information
Call the Function Function Call