home *** CD-ROM | disk | FTP | other *** search
/ UnrealScript Game Programming All in One / UnrealScriptGameProgrammingAllInOne.iso / UGPAIOListings / UGPAIOListingsCh16 / CH16LIST / Classes / CH16_02LIST.uc < prev    next >
Encoding:
Text File  |  2006-03-09  |  2.0 KB  |  85 lines

  1. // %PARAMETERS = "CH16LIST C:\UT2004"
  2. //Identifies the package
  3. //CH16_02LIST.uc
  4.  
  5. class CH16_02LIST extends Commandlet;
  6.  
  7. //#1
  8. //Declaration of struct at class scope
  9.   struct Play{
  10.      var string szTitle;            //struct members
  11.      var string szAuthor;
  12.      var int    iReference;
  13.      var int    iCastNumber;
  14.      var string szPrimeChar;
  15.   };
  16.  
  17. function int Main(string Args){
  18.  
  19.   //#2
  20.   //Declaration of abstract identifier of the type Play
  21.   local Play PlayA, PlayB, PlayC;
  22.   local Array<Play> rgPlaySet;
  23.   local int iCtr, iLoc;
  24.  
  25.   //#3
  26.   //Definition of struct members
  27.  
  28.   PlayA.szTitle = "Electra";
  29.   PlayA.szAuthor = "Sophocles";
  30.   PlayA.iReference = 156;
  31.   PlayA.iCastNumber = 7;
  32.   PlayA.szPrimeChar = "Electra";
  33.  
  34.   PlayB.szTitle = "Oedipus the King";
  35.   PlayB.szAuthor = "Sophocles";
  36.   PlayB.iReference = 99;
  37.   PlayB.iCastNumber = 14;
  38.   PlayB.szPrimeChar = "Iocasta";
  39.  
  40.  //Then assign them to an array
  41.   rgPlaySet[0] = PlayA;
  42.   rgPlaySet[1] = PlayB;
  43.  
  44.  
  45.   //#4 Assign a iReference to the array
  46.   rgPlaySet[2] = PlayC;
  47.  
  48.   //Then assign items to members directly
  49.   rgPlaySet[2].szTitle = "Antigone";
  50.   rgPlaySet[2].szAuthor = "Sophocles";
  51.   rgPlaySet[2].iReference = 131;
  52.   rgPlaySet[2].iCastNumber = 10;
  53.   rgPlaySet[2].szPrimeChar = "Antigone";
  54.  
  55.   Log(Chr(10) $ "   CH16_02LIST -- Structures and Arrays" $ Chr(10));
  56.   //Call of function to display one structure
  57.  
  58. //#5
  59.  
  60.   //Use of the array to print the array of Play items
  61.   iLoc = rgPlaySet.Length;
  62.   iCtr = 0;
  63.   while(iCtr < iLoc){
  64.      showInfo(rgPlaySet[iCtr] );
  65.      iCtr++;
  66.   }
  67.  
  68.   return 0;
  69. }
  70.  
  71. //#6
  72. //function receives struct and retrieves members
  73. function int showInfo(Play playName){
  74.    Log(Chr(10));
  75.    Log("  Name:              " $ playName.szTitle );
  76.    Log("  szAuthor:          " $ playName.szAuthor );
  77.    Log("  Page ref:          " $ playName.iReference );
  78.    Log("  Number in cast:    " $ playName.iCastNumber );
  79.    Log("  Character example: " $ playName.szPrimeChar );
  80.  
  81.    return 0;
  82. }
  83.  
  84.  
  85.