Üres függvény írása paraméterekkel a VEXcode Pro V5-ben

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.

Előfordulhat, hogy konkrét információkat szeretne adni a funkcióhoz. Ez lehetővé teszi a funkció számára, hogy a híváskor kapott információk alapján megfelelően hajtsa végre a feladatát. A következő minta bemutatja, hogyan működik.


Minta: A program paraméterekkel rajzol egy mosolygó arcot, amelyet megmutat

A következő példa a megfelelően használt globális változókra is példát mutat.

Felhasználó által definiált függvény használata nélkül:

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.
    */
}

Felhasználó által definiált funkcióval:

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);
  }  
}

Itt látható a main() hívó függvény logikai folyamatának sorrendje:

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

Last Updated: