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

Started by
7 comments, last by jpetrie 15 years ago
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!
Advertisement
Would it really be so horrible to load this stuff from data files instead?
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
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!
Did you try using the readonly keyword?
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?)
Not that I know of. In C#, there's no concept of a statically-sized array like there is in C++.
NextWar: The Quest for Earth available now for Windows Phone 7.
Why do you WANT a statically sized array like that, anyway?
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
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
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.

This topic is closed to new replies.

Advertisement