צה הבעיה בקוד הבא:
הקומפיילר אומר לי שאני משתמש במשתנה לא מאותחל בשורה שאני אסמן ב*****************. פתרתי את הבעיה על-ידי הוספת איתחול, אך לא ברורה לי הסיבה לכך. Inventory הוא ArrayList.
הקומפיילר אומר לי שאני משתמש במשתנה לא מאותחל בשורה שאני אסמן ב*****************. פתרתי את הבעיה על-ידי הוספת איתחול, אך לא ברורה לי הסיבה לכך. Inventory הוא ArrayList.
public bool equipItem (string item_name) { Item TempItem; //Check Item exists in inventory for(int index=0;index<Inventory.Count;index++) { TempItem = (Item)Inventory[index]; if (TempItem.ItemName==item_name && isItemWeaponORArmor(TempItem)) { Inventory.RemoveAt(index); break; }//END OF IF }//END OF FOR //Check if item is Weapon ->switch between weapons if (TempItem is Weapon)//************TEMPITEM is the problem { //Check if Actor has weapon if (ActorWeapon==null) { ActorWeapon=(Weapon)TempItem; } else { swapItems(TempItem,ActorWeapon); Inventory.Add(TempItem); } return true; }//END OF FIRST BIG IF