Error Code CS0029 Please Help

ItsDurry

New member
Joined
May 25, 2021
Messages
3
Programming Experience
Beginner
I've been searching for days now to try find a fix to this. Nothing on YouTube, Google or any forums pages has worked so if you have any idea ide love to hear it!.
C#:
public InventorySlot (InventoryObject _item,int _amount)
{
    item = _item;
    amount = _amount;
}

public void AddAmount(int value)
{
    amount += value;
}
 
Last edited by a moderator:
How did you declare amount? Specifically, what is it's type?

The documentation for the error code seems to tell you exactly why you would get the error.

Out of the curiosity, why would you search YouTube?
 
How did you declare amount? Specifically, what is it's type?

The documentation for the error code seems to tell you exactly why you would get the error.

Out of the curiosity, why would you search YouTube?
[System.Serializable]
public class InventorySlot
{
public ItemObject item;

public int amount;

the Console says: error CS0029: Cannot implicitly convert type 'InventoryObject' to 'ItemObject'

and i searched youtube because i couldnt find anything else on google/Forums
 
The error message is telling you exactly what the issue is so what's the problem? Why have you declared the field and the parameter as different types in the first place? If they are supposed to be different types, why do you think that you can assign one to the other?
 
I suspect our OP forgot to implement inheritance somewhere.
 
True, you can't assign an apple to an orange, or on orange to an apple, but you can assign an apple to fruit, and an orange to a fruit.

C#:
class Fruit
{
}

class Apple : Fruit
{
}

class Orange : Fruit
{
}

:

Fruit fruit = new Apple();

var fruitBasket = new List<Fruit>();
fruitBasket.Add(new Apple());
fruitBasket.Add(new Orange());
 
You are excusing stupidity.

I will refrain from elaborating what should be inherently obvious other than your example.

Do you squeeze the tit of a cow and expect to get milk or orange juice?
I came here for help not to get absolutely flamed.
Thanks for the help though ?
 
If you're learning to programme code, then you would and should have learned about the different types in early chapters. Instead of skipping chapters and then relying on people online telling you why something doesn't work when it's something you should know. You should spend time reading all materials especially covering fundamental basics or else you will get nowhere in programming.

You're not being flamed, you are being cross checked on what any learner should know, and its dissatisfying that people today continue to skip the fundamentals and instead dive into the deep end. I so happen to be a little blunt about expressing these things. There is not one person on this board who can say that I don't encourage learning, or try to steer people onto the right road because It's known that I thrive on educating people who want to learn, and I have almost 2000 posts to show for it. The fact is, there is no excuse for not knowing the answer to your question. With an abundance of online tutorials, and documentation provided on this digital library (the web), there is no excuse for not knowing the answer to simple or trivial questions such as yours. Not to mention, they have been answer a gazillion times already.

Now that's out of the way, look at your code.
C#:
Access Modifier:                                 Type:                                                               Type / Parameter value:

public                                            InventorySlot                                                 (InventoryObject _item, int _amount)

public                                            ItemObject


Oranges don't grow on apple trees. Therefor you can't pass an InventoryObject and expect to magically equally it to an ItemObject since they are two completely different types. Hence the self evident error : CS0029: Cannot implicitly convert type 'InventoryObject' to 'ItemObject'
 
Back
Top Bottom