home *** CD-ROM | disk | FTP | other *** search
/ UnrealScript Game Programming All in One / UnrealScriptGameProgrammingAllInOne.iso / UGPAIOListings / UGPAIOListingsCh15 / CH15LIST / Classes / CH15_02LIST.uc < prev    next >
Encoding:
Text File  |  2006-02-10  |  1.9 KB  |  80 lines

  1. // %PARAMETERS = "CH15LIST C:\UT2004"
  2. //Identifies the package
  3. //CH15_02LIST.uc
  4.  
  5. class CH15_02LIST extends Commandlet;
  6.  
  7. function int Main(string Args)
  8. {
  9.  
  10.  local Array<string> rgElectraCast;
  11.  local int iLen, iCtr;
  12.  iLen = 0;
  13.  //call Length to obtain number of characters
  14.  iLen = rgElectraCast.Length;
  15.   //Report number
  16.  
  17.  Log(Chr(10) $ "   CH15_02LIST -- Dynamic Array" $ Chr(10));
  18.  Log("   Initial length: " $ iLen $ Chr(10));
  19.  
  20.  //#2  Add elements to array
  21.  Log("   Add 3 characters: ");
  22.  rgElectraCast[0] = "Orestes";
  23.  rgElectraCast[1] = "Electra";
  24.  rgElectraCast[2] = "Chrysothemis";
  25.  
  26.  //call Length to obtain number of characters
  27.  iLen = rgElectraCast.Length;
  28.  
  29.  //Report number
  30.  Log("   Number of characters: " $ iLen);
  31.  
  32.  //Set counter and show characters
  33.  iCtr = 0;
  34.  for(iCtr = 0; iCtr < iLen; iCtr++){
  35.    Log("   " $ rgElectraCast[iCtr]);
  36.  }
  37.  
  38.  //#3
  39.  //Add  at the beginning
  40.  Log(Chr(10)  $ "   Add Clytemnestra to the start - Insert(0, 1): ");
  41.  rgElectraCast.Insert(0, 1);
  42.  rgElectraCast[0] = "Clytemnestra";
  43.  iLen = rgElectraCast.Length;
  44.  
  45.   //#4
  46.  //Add at the end
  47.  Log("   Add Aegisthus to the end - Insert(iLen, 1): ");
  48.  rgElectraCast.Insert(iLen, 1);
  49.  iLen = rgElectraCast.Length;
  50.  rgElectraCast[iLen-1] = "Aegisthus";
  51.  Log("       Insert[iLen-1] = Aegisthus" );
  52.  
  53.  //Report
  54.  iLen = rgElectraCast.Length;
  55.  Log("   Number of characters: " $ iLen);
  56.  iCtr = 0;
  57.  for(iCtr = 0; iCtr < iLen; iCtr++){
  58.    Log("      " $ rgElectraCast[iCtr]);
  59.  }
  60.  
  61.  //#5
  62.  Log(Chr(10)  $ "   Remove Clytemnestra and Aegisthus ");
  63.  Log("    - Remove(0,1)  - Remove (3, 1)");
  64.  
  65.  rgElectraCast.Remove(0,1);
  66.  iLen = rgElectraCast.Length;
  67.  rgElectraCast.Remove(iLen - 1,1);
  68.  
  69.  //Report
  70.  iLen = rgElectraCast.Length;
  71.  Log("   Number of characters: " $ iLen);
  72.  iCtr = 0;
  73.  for(iCtr = 0; iCtr < iLen; iCtr++){
  74.    Log("      " $ rgElectraCast[iCtr]);
  75.  }
  76.  
  77.  return 0;
  78. }
  79.  
  80.