Jump to content
  • Advertisement
Sign in to follow this  
Runicode

Display Item Attributes

This topic is 3271 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

One of the things I'm attempting to accomplish is when the player hovers over an item, it displays item attributes on screen, ex: Name, Description, Strength, etc... What would be the best way to read in this info? Should I pull this info from the objects data members or should I have the items all listed out in some file somewhere and read them in? How can I know what the item really is when I hover over it?

Share this post


Link to post
Share on other sites
Advertisement
You might want to mention some basic information like what programming language, platform and libraries you're using.

Share this post


Link to post
Share on other sites
The way I do it is I have a class representing each spot an item can be.. for instance, an inventory. The inventory holds data about each item (you can have it hold ALL the info or just information enough to identify what item it is, and retrieve the data from a 'factory' (if this confuses you, just imagine the inventory has a collection of items, which hold data like strength, attack power, name, etc). When you check to see if a mouse hovers, your inventory position should be based on the top left corner, so you find where your mouse is relative to your inventory position. You calculate what 'spot' for items your mouse is at, and retrieve the item information based on where it is.

Share this post


Link to post
Share on other sites
Hi Crazyfool. That's the way I have it designed now. I have an Item base class which all others are derived from. The class contains data members for the items attributes. I guess what I'm really confused about is where I should store all the item information. Let's say I have 100 items in the game, but right now the player only knows about 10 of them and only because they are stored in the players inventory. Where would I read in new items from? I'm not sure if I should just hard code multiple objects or keep them listed out in a file and read them in as needed.

To give you an example... let's say a creature's loot table has 2 possible items each with a 50% chance of dropping. The creature is killed and item 1 drops. So I need to create that object now. So where should I get the data from to initialize the object? From a file mabye or should the object really already exist in memory prior to exposing it to the player?

I hope I'm making sense. Thanks for your help.

Share this post


Link to post
Share on other sites
Quote:
To give you an example... let's say a creature's loot table has 2 possible items each with a 50% chance of dropping. The creature is killed and item 1 drops. So I need to create that object now. So where should I get the data from to initialize the object? From a file mabye or should the object really already exist in memory prior to exposing it to the player?
It sounds like you're asking how best to spawn new entities during the game, right? If so, I think in most cases it would be preferable to have the item already in memory, rather than loading it from a file on demand.

A fairly common way to approach this problem (IMX, at least) is to create a 'prototype' entity for each different entity type at the start of the game (or level or whatever), and then make copies of that prototype as needed. In the simplest scenario, once you've made the copy, you won't have to change anything about the copy other than its transform (which will determine its position and orientation relative to the world).

If the prototypes are polymorphic and stored by pointer or smart pointer, you can use the 'virtual constructor' idiom to make (deep) copies of the prototypes.

Share this post


Link to post
Share on other sites
I have a factory class which holds the information for all items, and I can access them by name, item id, etc. Whenever I want to get the information I simply access the item factory which has all items.

So it goes a little something like this:
1. Game starts, load all items into the factory class
2. Player does something that rewards an item
3. We know something about the item
4. Get item information based on the something we know from the item factory

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!