home *** CD-ROM | disk | FTP | other *** search
/ UnrealScript Game Programming All in One / UnrealScriptGameProgrammingAllInOne.iso / UGPAIOListings / UGPAIOListingsCh19 / CH19LIST / Classes / Script.uc < prev   
Encoding:
Text File  |  2006-02-25  |  2.9 KB  |  104 lines

  1. // %PARAMETERS = "CH19LIST C:\UT2004"
  2. //Identifies the package
  3. //Script.uc
  4.  
  5. //#1
  6. //Class preconditions:
  7. //This class depends on the Element class.
  8. //The test driver for this class is CH19_03LIST
  9.  
  10. class Script extends Commandlet;
  11.  
  12. //#2 Class attributes
  13. var private Array<Element> rgElements;
  14. var private int iLen;
  15.  
  16. //#3
  17. //------------------------getElement---------------------
  18. public function Element getElement(int elNum){
  19.     local Element locElement;
  20.     local int iCtr;
  21.     //if it does not exit, return a zero item
  22.     locElement = new class'Element';
  23.     locElement.setElementNum(0);
  24.     //Verify the number of items in the array
  25.     iLen = rgElements.Length;
  26.     iCtr = 0;
  27.     while(iCtr < iLen){
  28.        if(elNum == rgElements[iCtr].getElementNum()){
  29.          locElement = rgElements[iCtr];
  30.          break;
  31.        }//end if
  32.        iCtr++;
  33.      }//end while
  34.      return locElement;
  35. }//end getElement
  36.  
  37. //#4
  38. //-------------------addElement------------------------
  39. public function addElement(Element elToAdd){
  40.  
  41.      //insert element at end of array
  42.      iLen = rgElements.Length;
  43.      if(elToAdd.getElementNum() != 0){
  44.          rgElements.Insert(iLen, 1);
  45.          //insert the new element
  46.          iLen = rgElements.Length;
  47.          rgElements[iLen - 1] = elToAdd;
  48.       }else{
  49.          Log("   Cannot add an element with no identifier number.");
  50.       }
  51. }//end addElement
  52.  
  53.  
  54. //#5
  55. //--------------------logElementInfo-------------------
  56. //Print the basic contents of an element
  57. private function logElementInfo(Element elToLog){
  58.   //Do not try to access an element tha does not exist
  59.   if(elToLog.getElementNum() != 0){
  60.       Log("    "  $ elToLog.getElementNum() );
  61.       Log("    "  $ elToLog.getElementName() );
  62.       Log("   ["  $ elToLog.getDirection() $ "]");
  63.       Log("    "  $ elToLog.getSpeech() );
  64.    }else{
  65.       Log("   Element not found");
  66.    }
  67. }
  68.  
  69. //#6
  70. //--------------------showBasicElement------------------
  71. //Use the number of an element to show it for display
  72. public function showBasicElement(int elNum){
  73.      logElementInfo(getElement( elNum));
  74. }//end getElement
  75.  
  76. //#7
  77. //--------------------getLength------------------
  78. //Obtain the length of the Script Elements array
  79. public function int getLength(){
  80.     return iLen;
  81. }
  82.  
  83. //#8
  84. //--------------------removeElement------------------
  85. public function removeElement(int elNum){
  86.     //Delete the element with the specified identifer
  87.     local int iCtr;
  88.     //confirm current length;
  89.     iLen = rgElements.Length;
  90.     iCtr = 0;
  91.      if( getElement(elNum).getElementNum() != 0){
  92.        while(iCtr <= iLen){
  93.         //when you find the number
  94.           if(elNum == rgElements[iCtr].getElementNum()){
  95.           Log("   Deleting: " $ rgElements[iCtr].getElementNum());
  96.           rgElements.Remove(iCtr, 1);
  97.           break;
  98.         }//end if
  99.        iCtr++;
  100.       }//end while
  101.      }//end if
  102.       iLen = rgElements.Length;
  103. }
  104.