Inventory system malfunction; cannot convert method to return bool instead...

I’m following AwfulMedia’s new inventory system tutorials and everything was going quite well… I finished the series and found an extension tutorial series based on his inventory system that allows equipping items, etc… The tutorial’s author isn’t very clear and I am getting many errors but one of them remains after clearing:

Assets/Inventory/Scripts/CharacterPanel.cs(30,62): error CS0019: Operator `!=' cannot be applied to operands of type `void' and `null'

Here are the segments of the scripts concerning this error:

CharacterPanel.cs

	public void EquipItem(Item newEquip, int uniqueId) {
		foreach(Transform child in transform) {
			try {
				if(child.GetComponent<EquipmentSlot>().equipmentType == newEquip.Type) {
					EquipmentSlot equip = child.GetComponent<EquipmentSlot>();
					//Checks if an item isn't already equipped
					if(equip.equippedItem.ID == -1) {
						inventory.RemoveUniqueItem(uniqueId, newEquip.ID);
						equip.equippedItem = newEquip;
					} else {
						//Remove the item to be equipped from the inventory
						inventory.RemoveUniqueItem(uniqueId, newEquip.ID);
						//Assign the current item to a holding variable
						Item holder = equip.equippedItem;
						//Adds the current item to the inventory
						if(inventory.AddItem(holder.ID) != null) {
							equip.equippedItem = newEquip;
						} else {
							inventory.AddItem(newEquip.ID);
						}
					}
					child.GetChild(0).GetComponent<Image>().sprite = newEquip.Sprite;
					child.GetChild(0).GetComponent<Image>().color = new Color(255, 255, 255, 1);

					stats.extraStrength = newEquip.Strength;
					stats.extraIntelligence = newEquip.Intelligence;
					stats.extraDamage = newEquip.Damage;
					stats.extraSpellDamage = newEquip.SpellDamage;
					stats.extraHealth = newEquip.ExtraHealth;
					stats.extraMana = newEquip.ExtraMana;
				}
			}
			catch {}
		}
	}

Inventory.cs

	public void AddItem(int id) {
		Item itemToAdd = database.FetchItemByID(id);
		if(itemToAdd.Stackable && CheckIfItemIsInInventory(itemToAdd)) {
			for(int i = 0; i < items.Count; i++) {
				if(items*.ID == id) {*

_ ItemData data = slots*.transform.GetChild(0).GetComponent();_
_
data.amount++;_
_
data.transform.GetChild(0).GetComponent().text = data.amount.ToString();_
_
break;_
_
}_
_
}_
_
} else {_
_
for(int i = 0; i < items.Count; i++) {_
_ if(items.ID == -1) {
items = itemToAdd;
GameObject itemObj = Instantiate(inventoryItem);
itemObj.GetComponent().item = itemToAdd;
itemObj.GetComponent().amount = 1;
itemObj.GetComponent().slot = i;
itemObj.transform.SetParent(slots.transform);
itemObj.transform.position = Vector2.zero;
itemObj.GetComponent().sprite = itemToAdd.Sprite;
itemObj.name = itemToAdd.Title;
break;
}
}
}
}*_

I believe it has to do with the AddItem method being void and not bool, but changing it to bool gives the “Not all code paths return a value” error instead… can someone help me please? Thanks :slight_smile:

Your problem is here:

if(inventory.AddItem(holder.ID) != null) {

That’s because the “AddItem” method doesn’t return anything - it’s a “void” method. Since the method doesn’t return anything, you can’t compare its result to anything - including “null”.

I’m not exactly sure what you’re trying to determine with that line of code, but that certainly won’t work.