100 likes | 113 Views
Learn about functions and methods that return different types of values such as number, boolean, and objects. Understand how these functions work and when to use them. Explore built-in functions for checking conditions, getting information about objects, and using proximity and spatial relationships. Create your own functions to add custom behavior to your programs.
E N D
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 • Relation to other objects • Size • Spatial Relationship • Point of View
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.
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