Virtual Robot Simulator Official Guidebook
  • Coverpage
  • Introduction
  • FTC
    • Centerstage Game and Basic Rules
    • Powerplay Game and Basic Rules
  • VRS
  • Programming
    • User Interface
    • Blocks
      • LinearOpMode
      • Gamepad
      • Actuators
        • DcMotor
        • CRServo
        • Servo
      • Sensors
        • DistanceSensor
        • IMU
        • IMU-BNO055.Parameters
        • REV Color/Range Sensor
        • TouchSensor
      • Utilities
        • Acceleration
        • AngleUnit
        • AngularVelocity
        • Axis
        • Color
        • Orientation
        • PIDFCoefficients
        • Position
        • Range
        • Telemetry
        • Time
        • Vector
        • Velocity
      • Logic
      • Loops
      • Math
      • Text
      • Lists
      • Variables
      • Function
      • Miscellaneous
    • Basic Lessons
      • Drivetrain
      • IMU
      • Color Sensor
      • Telemetry
      • Range Sensor
      • Touch Sensor
      • Servo
      • CRServo
      • DCMotor
      • Logic and Loops
      • Functions
      • Tele-Op Control
    • Advanced Lessons
      • Advanced Tele-Op Control
    • Video Lessons
    • Simulation
    • Exploratory Activities
      • Wandering Robot
  • Robot Arena
    • Single Player
    • Activities
      • Coding Competition
      • CenterStage Competition
  • Conclusion
  • Author
  • Other Editions
Powered by GitBook
On this page
  1. Programming
  2. Blocks

Function

PreviousVariablesNextMiscellaneous

Last updated 9 months ago

A function is a reusable block of code that performs a specific task. It's like a mini-program within your main program. You give it a name, define what it does, and then you can "call" or use it multiple times in your code without having to write the same instructions repeatedly.

to do something

Creates a function with no output.

Key points:

  • You can change “do something” to a unique tag for your future reference.

  • This function has no output.

to do something return

Creates a function with an output.

Key points:

  • You can change “do something” to a unique tag for your future reference.

  • This function returns a value as specified.

if return

If a value is true, then return the second value.

Key points:

  • This block can only be used within a function.

  • When the condition is true and the value is returned, no other blocks will be executed anymore.

runOpMode

Run the user defined function “runOpMode”. You may have defined a function with a different name. The user defined function name will auto populate in the functions list.