Creating new set of enums from an existing set at runtime, how would I do this?

I don’t know if you can do this or if I need to use something other than enums.
Can I define one enum so it has two values?
Here is an example of what I would like to have:
a set of five enums and those five enums representing two values, the values can match values of the other enums.
with those five enums you pick lets say two and make a new set of enums with those two, and then compare the values between this new set and rank them accordingly.
I get slightly confused just trying to write this text, I hope someone can understand it.

My first concern is I don’t know if enums can have two values at the same time and if they cannot, what is my alternative?
Secondly, I need to be able to compare the values of the new set I want to create with the selected variables. From what I read people have a lot of problems with this and I didn’t see a single question on this actually being answered, should I run?

Maybe you should try to understand your problem yourself first. > I get slightly confused just trying to > write this text, I hope someone can > understand it How could we if you can't?

Why don't you instead state what final goal you want to achieve, rather than what you want to do? Honestly you're not making much sense. You can't compare values of different enums even if these values are named equally. Also AFAIK you cannot dynamically modify enums.

2 Answers

2

Enums have one value and they have to be byte, sbyte, short, ushort, int, uint, long, or ulong. Those are all just integer values btw, they just store a larger range of numbers.

Sound to me like you could just have a 2D array (an array of arrays) with the 5 arrays you need to begin with then you add to a 2 the new numbers you create. A list is like an array but you can resize them.

You’re going to need to do a bit more research, it is quite a bit to explain here I’m afraid.

Hope that helps!

Oops accidentally deleted your last comments... I finally changed the size check, minSize now defines the percentage of the starting size. I have mixed up the z and the y axis in my previous code comments. Hope everything works now and is clear.

(Please read the comments in the question first for more context about this answer)

Hi, well, see now we got a better picture. First you have these fruits that have certain qualities to each. So you want to make a class or struct to represent these fruits and their qualities/properties:

class Fruit {
        public string name="";
        public float moist=0f;
        public float freshness=0f;

        public Fruit (string name, float moist, float freshness) {
            this.name=name;
            this.moist=moist;
            this.freshness=freshness;
        }
    }

Then you want to modify the Set class to hold these fruits. So instead of using int, you will use Fruits:

class Set {
        List<Fruit> fruits=new List<Fruit>();

        public void AddFruits (params Fruit[] fruits) { //This will accept either an array or an indefinite number of parameters
            this.fruits.AddRange(fruits);
        }

        public List<Fruit> Fruits () { //Return fruits list
            return fruits;
        }

        public void AddSet (Set set) { //Adds a Set fruits to this Set fruits
            fruits.AddRange(set.Fruits());
        }

        public static Set MergedSets (params Set[] sets) { //Returns a new Set which is the result of merging several Sets
            Set mergedSet=new Set();

            foreach(Set set in sets)
                mergedSet.AddSet(set);

            return mergedSet;
        }

        public List<Fruit> GetFruitsByMoistAsc () { //Returns the list of fruits according to their moist, ascending
            List<Fruit> fruits=new List<Fruit>();
            fruits.AddRange(this.fruits);

            fruits.Sort((x, y) => x.moist.CompareTo(y.moist));

            return fruits;
        }

        public List<Fruit> GetFruitsByMoistDsc () { //Returns the list of fruits according to their moist, descending
            List<Fruit> fruits=new List<Fruit>();
            fruits.AddRange(this.fruits);

            fruits.Sort((x, y) => y.moist.CompareTo(x.moist));

            return fruits;
        }

        public List<Fruit> GetFruitsByFreshnessAsc () { //Returns the list of fruits according to their freshness, ascending
            List<Fruit> fruits=new List<Fruit>();
            fruits.AddRange(this.fruits);

            fruits.Sort((x, y) => x.freshness.CompareTo(y.freshness));

            return fruits;
        }

        public List<Fruit> GetFruitsByFreshnessDsc () { //Returns the list of fruits according to their freshness, descending
            List<Fruit> fruits=new List<Fruit>();
            fruits.AddRange(this.fruits);

            fruits.Sort((x, y) => y.freshness.CompareTo(x.freshness));

            return fruits;
        }
    }

Then you would first define your fruits, and then add them to your fixed sets of fruits, the baskets. Then you would add all the fruits from all the chosen baskets into one big pile. Then pick whatever fruit by whatever attribute:

public void blah() {

        //Define fruits for a basket
        Fruit apple1=new Fruit("Golden Delicious", 80f, 70f);
        Fruit apple2=new Fruit("Red Delicious", 60f, 20f);
        Fruit apple3=new Fruit("Gala", 40f, 78f);
        Fruit apple4=new Fruit("Fuji", 50f, 22f);
        Fruit apple5=new Fruit("Granny Smith", 33.5f, 37f);
        Fruit apple6=new Fruit("Honeycrisp", 24f, 91f);

        //Add fruits to basket
        Set apples2B=new Set();
        apples2B.AddFruits(apple1, apple2, apple3, apple4, apple5, apple6);

        //More fruits... more baskets...
        Set kiwi3G=new Set();

        //ETC.

        //After all 4 baskets were chosen, merge all baskets fruits into one pile
        Set fruitsPile=Set.MergedSets(apples2B, kiwi3G);

        //I want to pick the most fresh fruit from the pile:
        Fruit freshestFruit=fruitsPile.GetFruitsByFreshnessDsc()[0];

        //ETC.

    }

I think this would be a valid way of handling the situation. If you need further help with different areas of the matter, like setting up drop drown boxes and the like, you should probably open new questions with more specific questions.

As you said, arrays are of fixed length once they’re initialized, although I presume C# provides ways to dynamically grow them, but usually you’re better off sticking to Lists as they’re far more manageable. Drawbacks of lists… they’re possibly a little slower, and take up more memory, but usually nothing one should be too concerned about. For all I know C# could be handling arrays and list in virtually the same way internally. In the old days you could definitely assert the aforementioned about arrays and vectors in C/C++ but I’m not quite sure to what extent this applies to C#. As for enums, they’re really just definitions you would use at build time, not actual values you can pick at run time, I hope I’m making some sense… something like flags to guide your code, but not actual values. So in the present case I don’t think they have much use.

I'll test that out now.

For some reason, the Z and Y values are swapped on my model. Instead of scaling the destructible part on both horizontal values, it scales it on the X axis and the Y axis. This results in the destructible part of the Zebetite looking flat when it is looked at from one side.