is this code is good to follow the comments, is there any possible flaws? (like breaking from the fixed loop of calling and stuf ehich may cause problems)Code:void AddItem(int A) //the arug' the amount you want to add { int B; //used to contain the subscribed amount amount += A; //adds to the amount if( amount > stackSize ) //if the amount is greater then the stacksize { B = amount - stackSize; //it subscribes stackSize from the amount to find out by how much greater amount -= B; //and then it subscribes the subscribed amount from the amount GetItem(B); //which after then it takes the subscribed amount and calls and calls GetItem so itll add the subscribes amount to a new slot } } void GetItem(int A) //the arug' indicates the amount of the item { for( int iii=0; iii != MAX_INV; iii++) //a "for" loop to travel around the slots(arrays) if( charInv[iii].id == 0 ) //if it finds an empy slot(array with NULL id) { charInv[iii] = *this; //it copies the item into the slot (representing the item with "*this") charInv[iii].additem(A); //and the addd the amount of the item break; //which after this it breaks the loop so it won't add the same item multiple items } //otherwise if the slot isn't empty itll start looking for another slot else if( charInv[iii].id == id) //if it finds slot with the same item(same id) if( charInv[iii].amount < stackSize) //if theres still space left in the stackSize(the amount is less then the stacksize) { charInv[iii].AddItem(A); //it adds the value to the item(by calling AddItem) break; //which after this it breaks the loop so it won't add the same item multiple items } //otherwise if theres no space left in stackSize itll look for another free slot }



LinkBack URL
About LinkBacks



