Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7820581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:20:56+00:00 2026-06-02T07:20:56+00:00

I’m making a multiplayer text game, and every player in the game is assigned

  • 0

I’m making a multiplayer text game, and every player in the game is assigned an inventory. The inventory is a simple linear linked list which contains the ID of the item and the state of the item in the game. For example, player1 could have a red car with 50% of fuel and it would be represented in the list as (5, 50) where 5 is the ID of a red car in the game and 50 is the amount of fuel of that specific car.

But this means the information of every item in the game should be saved in some data structure.

I thought of using something like

enum itemtype {car, gun, bullet, etc};
struct itemlist {
    itemtype type;
    char* name;
    int volume, weight;
} itemlist[];

And all the information of red cars (car, "Red car", 15m^3, 2000kg) would be stored in itemlist[5], because the ID for red cars is 5.

But there are different types of items in this game, so each item has its own properties. Cars would have (max_speed, acceleration) and bullets would have (mass, velocity, kinetic_energy). And some parts of the code need to access these specific properties in order to do stuff in the game.

So this means

  • getting the ID from the inventory
  • checking the array for specific properties of such item
  • do stuff with the retrieved properties

but I don’t know how to do that because there are different categories of items with different specific properties each one.

Adding an array to the struct wouldn’t help because properties can be anything, like strings or numbers. Adding a nested structure might be fine but there could be something that tries to use item[5].properties.max_speed and I’m not sure if this is safe, because someone could try to get the property max_speed from an item that doesn’t have it.

So, what’s the best way of storing general and specific properties for such list of items?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T07:21:01+00:00Added an answer on June 2, 2026 at 7:21 am

    Err, maybe I’m missing something here but isn’t this exactly what the union was built to do?

    Make each item in your list a union data type along the lines of:

    struct itemelem {
        itemtype type;
        union {
            cartype c;
            bullettype b;
        };
    };
    

    In that case, you would use type to identify what the element type was, so you could then access the correct union specifier, sort of a poor man’s polymorphism 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.