ROBOTC Features and Functions

From FIRE Wiki
Jump to: navigation, search

Here are some functions/features that will help with ROBOTC testing/development with Multibot.

Feel free to add feature requests on this page as well.

Power Of Function

long new_pow(int x, int p)
{
  int result = x;
  for(int count = 0; count < p-1; count++)
  {
    result *= x;
  }
  return result;
}

String to Int Function (requires pow)

int new_atoi(string IncomingData)
{
  const ubyte charToInt = 48;
  int num = 0;
  int digits = strlen(IncomingData);
  long magnitude = new_pow(10, digits-1);

  for (int i = (digits - 1); i >= 0; i--)
  { 
    num += ((char)IncomingData - charToInt) * magnitude;
    magnitude /= 10;
    StringDelete(IncomingData, 0, 1);
  }
  return num;
}

Check Incoming Data to See if it's a Displayable Character

bool isRealChar(char byteToCheck)
{
  //Function to check if I'm getting a real ASCII displayable character
  if(byteToCheck >= 0x20 && byteToCheck <= 0x7E) return true;
  return false;
}

Code to Clean Up Two Parameters Separated by a Delimiter (example: /)

const string Delimiter = "/";

int getFirstParm(string sourceString1)
{
  ubyte DelimiterPos, LengthofString;

  int FinalValue1 = 0;

  DelimiterPos = StringFind(sourceString1, Delimiter);
  LengthofString = strlen(sourceString1);

  StringDelete(sourceString1,DelimiterPos,(LengthofString - DelimiterPos));

  FinalValue1 = new_atoi(sourceString1);

  return FinalValue1;
}

int getSecondParm(string sourceString2)
{
  int FinalValue2 = 0;
  
  StringDelete(sourceString2,0,StringFind(sourceString2, Delimiter) + 1);

  FinalValue2 = new_atoi(sourceString2);  
  
  return FinalValue2;
}

Feature Request: Int to String