- Home /
Override method for items in xml list?
I built an xml list for items in my game and want to run an "OnPickup" method that is different for certain items (Picking up a magic item will put a curse on you, but picking up a normal item won't, etc.) but I don't know how to do this? Obviously, since all my items inherit from the same basic item class which has an OnPickup method to add the item to the player's inventory, I figured I should just override that method for items with unique pickup interactions, but I don't know how to signal this in my code.
Do I have to create separate lists for items with different interactions, and a unique class that inherits from the basic item class? Is there a way to override the method from the main xml list? The whole reason I switched to xml was to keep from cluttering up my files with individual scripts for every item. Please help!
it depends on where the uniqueness starts. you said cursing you in case of a particular spell. do all items do something to you if anything? or to others, multiple, depending on one another...?
It's still early in development, but I currently have 3 different types of items, and only 1 of them doesn't have a special effect when picked up. The other two are items that should give quests when picked up, and items that should apply a buff or debuff to the player's stats. The other type of item does nothing and the OnPickup method just adds the item to the player's inventory. I'm thinking about moving that functionality to its own method and just calling it in OnPickup, so that I don't have to type the same code when I override OnPickup for the other two types of item.
and what information is it that you serialize?