Hello everyone. I’m having a bit of a problem, and I can’t seem to fix it myself. Trying to make an inventory script for my game I get the following error on line 58:
Operator “==” cannot be used with a left hand side of type ‘InventoryItem’ and a right hand side of type ‘SystemObject’
This is my script:
@script AddComponentMenu ("Inventory/Inventory")
enum InventoryItem{
DEBUG_ITEM,
TRASH_SMALL,
TRASH_BIG,
CHOCOLATE_BAR,
ENERGY_DRINK,
BATTERY_SMALL,
BATTERY_LARGE,
REPAIR_KIT,
NUTS_AND_BOLTS,
AMMO_BULLETS,
COUNT_NUM_ITEMS
}
var inventory: int[];
// LINKS TO BUDDY'S STATUS MANAGER
var buddyPlayerStatus: BuddyStatus;
buddyPlayerStatus = GetComponent(BuddyStatus);
// LINKS TO PAL'S STATUS MANAGER
var palPlayerStatus: PalStatus;
palPlayerStatus = GetComponent(PalStatus);
private var chocolateBarAmount = 2.0;
private var energyDrinkAmount = 5.0;
private var batterySmallAmount = 20.0;
private var batteryLargeAmount = 100.0;
private var nutsAndBoltsAmount = 2.0;
private var repairKitAmount = 5.0;
function Start(){
inventory = new int[InventoryItem.COUNT_NUM_ITEMS];
for (var item in inventory){
inventory[item] = 0;
}
// STARTING ITEMS
inventory[InventoryItem.CHOCOLATE_BAR] = 2;
inventory[InventoryItem.BATTERY_SMALL] = 2;
inventory[InventoryItem.NUTS_AND_BOLTS] = 2;
}
// PICK UP ITEMS
function GetItem(item: InventoryItem, amount: int){
inventory[item] += amount;
}
// USE ITEMS
function UseItem(item: InventoryItem, amount: int){
if(inventory[item] <= 0) return;
inventory[item] -= amount;
switch(item){
case InventoryItem.CHOCOLATE_BAR:
buddyPlayerStatus.AddHealth(chocolateBarAmount);
break;
case InventoryItem.ENERGY_DRINK:
buddyPlayerStatus.AddHealth(energyDrinkAmount);
break;
case InventoryItem.BATTERY_SMALL:
palPlayerStatus.AddBattery(batterySmallAmount);
break;
case InventoryItem.BATTER_LARGE:
palPlayerStatus.AddBattery(batteryLargeAmount);
break;
case InventoryItem.NUTS_AND_BOLTS:
palPlayerStatus.AddHealth(nutsAndBoltsAmount);
break;
case InventoryItem.REPAIR_KIT:
palPlayerStatus.AddHealth(repairKitAmount);
break;
}
}