Jump to content
  • Advertisement
Sign in to follow this  
miruim

[.net] Constant (Arrays of?) Structures in C#

This topic is 3472 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

Hi there guys, I'm making a game where I have many races, each one having racial maximums for each attribute. It's a MUD and looking at some C sources I found out they just use a constant structure or something. Well, I'm coding in C# and at the moment the closest I got to what I want was to declare a static list/array. The code is like this:
namespace Workshop
{
    enum EAttribute : byte { Body, Agility, Reaction, Strength, Charisma, Intuition, Logic, Willpower, Initiative }
    struct SAttribute
    {
        public string Name;
        public string Name3;
    }

    class Sheet
    {
        // Static Stuff
        #region Attribute Data Table
        public static SAttribute[] SAttributeTable = new SAttribute[9]
        { 
            new SAttribute { Name = "Body",        Name3 = "BOD" },
            new SAttribute { Name = "Agility",     Name3 = "AGI" },
            new SAttribute { Name = "Reaction",    Name3 = "REA" },
            new SAttribute { Name = "Strength",    Name3 = "STR" },
            new SAttribute { Name = "Charisma",    Name3 = "CHA" },
            new SAttribute { Name = "Intuition",   Name3 = "INT" },
            new SAttribute { Name = "Logic",       Name3 = "LOG" },
            new SAttribute { Name = "Willpower",   Name3 = "WIL" },
            new SAttribute { Name = "Initiative",  Name3 = "INI" },
        };
        #endregion
... and so it goes. Is that as far as C# can go for constant stuff? What's the closest I can get to the way Rom (MUD) defines its constants for the races, skills, classes constants, for example? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Could be, but wouldn't it be slower that way?

What do you suggest?

After reading them from the files I'll still have to store them somewhere. I thought I would end up in the same situation then...

Or are you suggesting that I read them from the files whenever I need to access them during the game?

I'm really really new to C# so any suggestion will be really appreciated.

Thanks again!

Share this post


Link to post
Share on other sites
Yup, readonly would work (I think), but that wouldn't solve my problem. I was reading my post and I think I wasn't very clear.

The problem is that I am creating what in C# is like a pointer, I think. And that obviously can't be constant. It's an array without declared size, which is expandable.

PROBLEM:
How to create a constant list of structures who, by their turn, contain many members, including structures as members, that's fixed in size? (Maybe being able to define their content upon initialization/declaration?)

Share this post


Link to post
Share on other sites
Well I thought it would save up on memory. But I guess I can't, heh. I've searched a lot but no solution. Maybe it's not possible in C#. :P

Share this post


Link to post
Share on other sites
Quote:

Well I thought it would save up on memory.

It won't, so I wouldn't worry about it.

Storing them in files and then loading them at runtime, as previously suggested, is really the ideal approach here.

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!