V5 Motor Encoders as a parameter in a function, like tsensors in robotC? PROS

Is there a way to set a motor as a variable for a function so I can use it multiple times with different encoders? In robotC there was the tsensors data type but I can’t find a way to do it in PROS.

Sure, like any object, you can write a function that takes a motor object as a parameter.

Here’s an example:

void move_motor(pros::motor& motorToMove, double amtToMove, int velocity){
    motorToMove.move_relative(amtToMove, velocity)

Probably a good idea to pass the motor object by reference (that’s what the & does) to avoid unnecessary overhead in copying the motor object every time this function is called.

Alternately, you could have the function take a pointer to the motor object, like this:

void move_motor(pros::motor* motorToMove, double amtToMove, int velocity){
    motorToMove -> move_relative(amtToMove, velocity);

Ah. Ok. I get it. Thank you.