Writing a Void Function with Parameters in VEXcode Pro V5

The VEX Visual Studio Code Extension has replaced VEXcode Pro V5, which is now end-of-life.

VEXcode Blocks and VEXcode Text remain actively developed and supported for all VEX platforms.

There will be times when you would like to give some specific information to the function. This will allow the function to perform its task accordingly based on the information received each time when it is called. The following sample will show how it works.


Sample: A program draws a smiley face to show using parameters

The following example also exemplifies global variables that are being used properly.

Without using a user-defined function:

int MaxX = 484, MaxY = 278;

int main() { 
  vexcodeInit();

  int centerX = MaxX/2, centerY = MaxY/2;

  //The face
	Brain.Screen.drawCircle(centerX, centerY, 100);

  //The left eye
  int space = 20; /*This provides the spacing for the eye relative to the top of the screen. You may adjust this however you want.*/
  centerX = MaxX/2+space;
  centerY = MaxY/2-30;
  Brain.Screen.drawCircle(centerX, centerY, 20);

  //The right eye  
  /*...you can continue to do the code for the right eye here*/

  //The smiley mouth
  /*...you can continue to do the code for the smiley mouth here
    ... etc.
    If you want to draw a different size, you will have to repeat the whole set of codes again.
    */
}

With a user-defined function:

int MaxX = 484, MaxY = 278;
const char Left=1, Right=2;

void drawFace(int size){
  /*...code for the face based on the size parameter from the caller funciton.*/

}

//side == Left or Right
void drawEye(char side){
  /*...code for the eye based on the size parameter from the caller funciton.*/
}

//side == Left or Right
void drawMouth(bool smile, int size){
  /*...code for the mouth based on the size parameter from the caller. This includes whether it is smiling or frowning, as well as the width.*/
}

int main() { 
  vexcodeInit();

  drawFace();
  drawEye(Left);
  drawEye(Right);

  //you can really have some fun with this...
  while (true){
    drawMouth(true, 30);
    wait(1000, msec);
    drawMouth(false, 30);
    wait(1000, msec);
  }  
}

Here shows the sequence of logic flow from the caller function main():

For more information, help, and tips, check out the many resources at VEX Professional Development Plus

Last Updated: