enum comparing

Hi guys, i was just trying to wrap my head around enums and was trying to use them for an equipment system and inventory system but seem to be getting this error no matter how i approach it.

Assets/Slot.cs(48,95): error CS0019: Operator ==' cannot be applied to operands of type DragHandler.Slot’ and `Slot.mySlot’

on script Slot

	public enum mySlot{
		invSlot,
		oneHand,
		TwoHand,
		offHand,
		head,
		shoulder,
		chest,
		legs,
		belt,
		boots
	};
	
	public mySlot itemType = mySlot.invSlot;



public void OnDrop (PointerEventData eventData)
	{

		if(item && DragHandler.itemBeingDragged.transform.GetComponent<DragHandler>().itemType == itemType)
		{
			print(transform.name);
//this one here is causing the error, 
		}

what i want to do is check both enums against each other to see if either one = each other without having to check each state otherwise it would be very messy is this possible without having to check each state?

i would of thought it would be something like i had done checking only the parameters i needed and everything else would return it back to its original slot in the inventory if it did not meet the state requirements

DragHandler Script

public enum Slot{
invSlot,
oneHand,
TwoHand,
offHand,
head,
shoulder,
chest,
legs,
belt,
boots
};

public Slot itemType = Slot.invSlot;

these are not the entire scripts as they would be very long to post but the required info i would believe that is needed to help sold this issue.

the 2 enums i want to check against eachother without having to check every single state. more or less

if it is a 1 Handed weapon, is it a sword dagger mace, etc, in most RPG games a mage cant wield a sword or a shield. but can store them in their inventory. what i want to do is compare the items enum against the players inventory and equipment slot enums. can this player equip this particular item etc. the way i want to do it is through enum comparing without having to go through every single possible combination rather than checkign the possible combinations only like if it is a offhand Sword you can only be put in the offhand weapon slot of a warrior or the inventory slot. but other rules will apply to other classes. that may break that condition.

You are declaring two different enums Slot and mySlot and the compiler cannot compare the two directly. This is because it cannot assume that two enums are describing the same thing. For instance suppose I had one enum for the Smith family, James Smith & Mary Smith, and another enum for the Miller family, James Miller & Mary Miller.

enum Smith {James, Mary};
enum Miller{James, Mary};

Then the following isn’t defined to the compiler

Smith james1=Smith.James;
Miller james2=Miller.James;
Debug.Log(james1==james2);

After all, in your case you would expect true to print but in this case you would expect false to print.

In your case you are defining two enums with the same enumerators so it seems like you just want to use one enum. Then you can just compare them directly, i.e.

enum Smith {James, Mary};

Smith james=Smith.James;
Smith mary=Smith.Mary;
Smith notMary=Smith.James;

Debug.Log(james==mary);
Debug.Log(james==notMary);

So you should remove Slot or mySlot and only use the enum you keep.