YEngine chars

CHARACTER DATATYPE

Enabled by: yoption chars;

Keyword: Discription
char primitive datatype

Permitted operators → result type (bool is an integer with value of 0 or 1):

   char == char    -> bool
   char != char    -> bool
   char <  char    -> bool
   char <= char    -> bool
   char >  char    -> bool
   char >= char    -> bool
   char + integer  -> char
   char - integer  -> char
   char - char     -> integer
   char + string   -> string
   string + char   -> string
   string[integer] -> char
   char ++         -> char
   char --         -> char
   -- char         -> char
   ++ char         -> char

Permitted casts:

   (integer)char
   (object)char
   (string)char
   (char)integer
   (char)object

Character constants:

   a single character between '' is permitted, eg, 'a', '4', '?'
   a newline can be generated by '\n'
   a tab can be generated by '\t' (it is a real tab char, not four spaces)
   backslash followed by any other character is that character, eg, '\'' and '\\' are valid
   an integer can be cast to a char for any others that are difficult to enter in the script editor, eg, (char)0xB1

Built-in functions:

   string xmrChars2String(object chararray, integer start, integer count)
       creates a string from an array of characters
           chararray = char[] array containing characters on input
           start     = offset in chararray to start at (zero based0
           count     = number of characters to extract
           returns the created string of length count
 
   xmrString2Chars(string srcstring, integer srcstart, object dstarray, integer dststart, integer count)
       extracts characters from a string and puts them in a character array
           srcstring = string containing characters on input
           srcstart  = where in srcstring to start reading at (zero based)
           dstarray  = char[] array to put characters in
           dststart  = where in dstarray to start writing at (zero based)
           count     = number of characters to extract
 
   Note:  The ''yoption objects;'' option must be enabled to access datatype char[].

Example:

   yoption advflowctl;  // 'switch'
   yoption chars;
   yoption objects;     // fixed-dimension arrays
   default {
       state_entry ()
       {
           char[] icat = new char[] { 'I', 'c', 'a', 't' };
           string line = "";
           for (integer i = 0; i < icat.Length; i ++) {
               char ch = icat[i];
               if (line != "") line += " ";
               switch (ch) {
                   case 'a' + 2: {
                       line += "see";
                       break;
                   }
                   case 't': {
                       line += "cat";
                       break;
                   }
                   default: {
                       line += ch;
                       break;
                   }
               }
           }
           llOwnerSay (line + '!');
       }
   }
QR Code
QR Code wiki:scripting_portal:chars (generated for current page)