Methods

Objective: Learn how to create your own methods

Go Back



What is a Method?

A method is a procedure, or a list of commands. (They are called functions in some languages. Same thing.)

Here is an example Java method called "sayStuff()" that prints several statements:

public static void sayStuff() { telemetry.addData("message", "I am saying stuff."); telemetry.addData("message2", "This is a new line."); telemetry.addData("message3", "More stuff."); }

Notice several things:



By the way, telemetry.addData() is a method. This method sends a message back to the driver station.

The addData() method takes two arguments, which are inputs for the function. In this case, whatever text goes inside both arguments will be printed on the driver station.

Notice that the text to be printed is enclosed in double quotes.