home *** CD-ROM | disk | FTP | other *** search
/ UnrealScript Game Programming All in One / UnrealScriptGameProgrammingAllInOne.iso / UGPAIOListings / UGPAIOListingsCh16 / CH16LIST / Classes / CH16_01LIST.uc next >
Encoding:
Text File  |  2006-02-17  |  1.7 KB  |  64 lines

  1. // %PARAMETERS = "CH16LIST C:\UT2004"
  2. //Identifies the package
  3. //CH16_01LIST.uc
  4.  
  5. class CH16_01LIST extends Commandlet;
  6.  
  7. //#1
  8. //Declaration of struct at class scope
  9. //An "abstract" data type
  10.   struct Play{
  11.      var string szTitle;            //struct members
  12.      var string szAuthor;
  13.      var int    iReference;
  14.      var int    iCastNumber;
  15.      var string szPrimeChar;
  16.   };
  17.  
  18. function int Main(string Args){
  19.   //#2
  20.   //Declaration of structure identifiers
  21.   local Play PlayA, PlayB;
  22.  
  23.   //#3
  24.   //Definition of struct members
  25.   PlayA.szTitle = "Electra";
  26.   PlayA.szAuthor = "Sophocles";
  27.   PlayA.iReference = 156;
  28.   PlayA.iCastNumber = 7;
  29.   PlayA.szPrimeChar = "Electra";
  30.  
  31.   PlayB.szTitle = "Oedipus the King";
  32.   PlayB.szAuthor = "Sophocles";
  33.   PlayB.iReference = 99;
  34.   PlayB.iCastNumber = 14;
  35.   PlayB.szPrimeChar = "Iocasta";
  36.  
  37.   Log(Chr(10) $ "   CH16_01LIST -- Structures" $ Chr(10));
  38.   //Call of function to display one structure
  39.  
  40. // #5
  41.   //passing the structs to a function for printing
  42.   showInfo(PlayA);
  43.   showInfo(PlayB);
  44.   return 0;
  45. }
  46.  
  47. //  #4
  48. //function receives struct and retrieves members
  49. function int showInfo(Play playArg){
  50.    local string szLocTitle;
  51.    //Redundant  step for demonstration
  52.    //Retrieve member value and assign it to a local identifier
  53.    szLocTitle = Caps(playArg.szTitle);
  54.    Log(Chr(10));
  55.    //Use of local identifier
  56.    Log("  Name of play:      " $ szLocTitle );
  57.    //Direct access of other member values
  58.    Log("  szAuthor:          " $ playArg.szAuthor );
  59.    Log("  Page ref:          " $ playArg.iReference );
  60.    Log("  Number in cast:    " $ playArg.iCastNumber );
  61.    Log("  Character example: " $ playArg.szPrimeChar );
  62.    return 0;
  63. }
  64.