Advertisement

Enums are pissing me off!

Started by August 07, 2000 01:07 PM
11 comments, last by a2k 24 years, 5 months ago
hey, this is so stupid and weird. i have an enumeration defined as: enum componentstate { Intact, InitializingLoss, Adrift, Exploded, Destroyed, None }; but, i wanted to move None as the first entry, to enum componentstate { None, Intact, InitializingLoss, Adrift, Exploded, Destroyed }; but when i do this, for some reason, the rest of my code thinks that the enumeration is still the previous arrangement, which causes all my pieces to fly around when they''re not supposed to. i''ve tried recompiling every file that requires the enumeration, and then building, but still, it doesn''t work. it still likes to keep it in the previous order. it bothers me that i can''t change the states around. has this happened to people? how do i fix it? it''s driving me nuts! a2k
------------------General Equation, this is Private Function reporting for duty, sir!a2k
It shouldn''t be behaving that way--IF every time you use the enum, your using its enum values (Intact, Adrift, None, etc.) and NOT the numerical values (i.e. converting to or from an int or something).

If you''ve recompiled everything and it''s not working, I would think you have an enum-to-int or int-to-enum conversion somewhere. Find it & kill it.
Advertisement
Just in case you don't know this yet:
Enum does this when you don't specify any values...

enum componentstate
{
None=0,
Intact=1,
InitializingLoss=2,
Adrift=3,
Exploded=4,
Destroyed=5
};

If you're just doing something like

        componentstate Ship=None; //really means Ship=0if (ship_hit){  Ship++;  showAnimationOrWhatever();  Ship++;  blah();}        


You shouldn't use the numerical values, use None, Destroyed, etc.

But maybe you already know how this works?...(probably) Are you certain you changed your other code to reflect the enumeration change? I'm just throwing out guesses here but maybe the real problem lies elsewhere... it might help to know how you're using the enumeration. Or maybe it's one of those "how come I didn't see that obvious mistake before?" errors, heh. I get those...

===========================================
As far as the laws of mathematics refer to reality, they are not certain, and as far as they are certain, they do not refer to reality.

-Albert Einstein

Edited by - Tebriel on August 7, 2000 2:45:35 PM
Just to ensure the obvious is stated, be sure to do a full rebuild of all the files that use this enum. If you''re using precompiled headers and you don''t do a full rebuild you''ll see behavior like you describe.
i''m using the strings, not the integer equivalents. uh, the recompiling thing, i''m sure i''m doing it right. using vc++6. i''ve compiled all files independently, and THEN i linked (built) them together, and it does the same weird wacky stuff (puts the components in a different state). anyway, thanks for the ideas though, i''ll keep trying...

a2k
------------------General Equation, this is Private Function reporting for duty, sir!a2k
Ok, i know this is stupid. But i have never heard of enum before. what is it, and what does it do?



=======================
Game project(s):
www.fiend.cjb.net
=======================Game project(s):www.fiend.cjb.net
Advertisement
If you have a variable that has a limited set of possible values which can be usefully referred to using labels, you can do this:

enum week {Mon, Tues, Wed, Thurs, Fri, Sat, Sun} thisWeek;

This declares an enumeration type called week and the variable thisWeek, which is an instance of the enumeration type week that can only assume the values specified between the braces. If you try to assign anything other than one of the set of values specified to thisWeek, it causes an error.

So you can do this--
thisWeek = Mon;
or
thisWeek = Tues;
etc

to assign variables. But what the compiler is really doing is something like this:
enum week {Mon=0, Tues=1, Wed=2, Thurs=3, Fri=4, Sat=5, Sun=6} thisWeek;

So technically you could also do this--
thisWeek = 0; or thisWeek = 1;
and this is equal to the two above assignments (it''s not a good way to use enumerated data types though).

You could also do this:
enum week {Mon=-2, Tues, Wed, Thurs, Fri, Sat=20, Sun} thisWeek;

the complier will automatically assign values to the others, counting UP. So Tues = -1 , Wed = 0,..., Sat = 20, Sun = 21, etc.

It''s kindof like having const variables that only work for the enumerated data type.

That''s about it... how''d you like the enumeration lesson?

Yeah I know... I''m pretty bored right now...

===========================================
As far as the laws of mathematics refer to reality, they are not certain, and as far as they are certain, they do not refer to reality.

-Albert Einstein
okay, i figured it out, guys. i''m so stupid. i had defined two enums. one for player state and one for component state, and for player state, i had a variable "Exploding" and in the component state, i had "Exploded," so i had checked for the wrong enumeration value.

geez. moral: even though you define two different enumerations, ALL are valid for whatever variable you are setting.


a2k
------------------General Equation, this is Private Function reporting for duty, sir!a2k
Aha, so it DID fall under the "how come I didn''t see that obvious mistake before?" category, heh. Hate those...

===========================================
As far as the laws of mathematics refer to reality, they are not certain, and as far as they are certain, they do not refer to reality.

-Albert Einstein
yep. =) sorry for wasting everybody''s time. it''s just that it was right before work, and i wouldn''t have been able to code at work.

a2k
------------------General Equation, this is Private Function reporting for duty, sir!a2k

This topic is closed to new replies.

Advertisement