1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

Enumerations.

Discussion in 'Programming' started by RestInPieces, Feb 10, 2002.

  1. RestInPieces

    RestInPieces New Member

    Joined:
    Sep 20, 2001
    Messages:
    65
    Likes Received:
    0
    Okay, lets say I've got an enum eMusicBand declared:

    enum eMusicBand
    {
    BAND_SickOfItAll,
    BAND_BadBrains,
    BAND_MinorThreat,
    BAND_Cro-Mags,
    BAND_Fugazi,
    };

    I've got a eMusicBand variable 'CurrentBand' and I've got a button in a UWindow, and now, if someone clicks the button, I want 'CurrentBand' to take the 'next' value, e.g. if CurrentBand==BAND_BadBrains , this would be BAND_MinorThreat. Is there a way to do this, except, of course, to write a long switch statement like

    Switch (CurrentBand)
    {
    Case BAND_MinorThreat:
    CurrentBand = BAND_CroMags;
    break;
    ...
    }

    I mean, something like CurrentBand++ (doesn't work of course), I thought this should be possible, since each item in an enum does have an int value...
    Thanks in advantage,
    RiP :)
     
  2. Captain Kewl

    Captain Kewl I know kewl.

    Joined:
    Feb 13, 2001
    Messages:
    794
    Likes Received:
    0
    Write a long If statement. :)
     
  3. RestInPieces

    RestInPieces New Member

    Joined:
    Sep 20, 2001
    Messages:
    65
    Likes Received:
    0
    I did. What a work ;)
     
  4. JoeWang(Kage)

    JoeWang(Kage) New Member

    Joined:
    Feb 10, 2002
    Messages:
    1
    Likes Received:
    0
    CurrentBand++ should work. Have you tried it? After all, enums are stored as a byte. Maybe you would have something like (CurrentBand++) % 5 to cycle through the enum without leaving its range.
     
  5. Eater1

    Eater1 Coder

    Joined:
    Oct 22, 2000
    Messages:
    176
    Likes Received:
    0
    ...and if that doesn't work, you can always write something like this:
    local byte tempb;

    tempb = CurrentBand;
    tempb++;
    CurrentBand = tempb;

    Or a long if statement.

    Eater.
     
  6. Techno JF

    Techno JF He Who Has Powerful Words

    Joined:
    Apr 8, 2001
    Messages:
    961
    Likes Received:
    0
    I agree with JoeWang. It should work just like a byte value. An enumerator is just a fancy way to work with constants instead of abstract numbers. Here's how to properly cycle through that list using the technique he mentioned. I hope it works.

    Code:
    if (CurrentBand==BAND_Fugazi)  //the last band in your enumerator
    {
       CurrentBand=BAND_SickOfItAll;
       //which will be changed to the first one in your enumerator
    }
    else
    {
       //otherwise, you just need it to be changed to the next one in your list
       CurrentBand++;
    }
    
     
  7. RestInPieces

    RestInPieces New Member

    Joined:
    Sep 20, 2001
    Messages:
    65
    Likes Received:
    0
    Thanks anyway...

    I tried both solutions, the CurrentBand++ one ("...types are incompatible with ++") and the CurrentBand=tempb one ("... bad expression in '=' "). Casting didn't work either :(
     
  8. Eater1

    Eater1 Coder

    Joined:
    Oct 22, 2000
    Messages:
    176
    Likes Received:
    0
    That's not possible... I KNOW you can assign byte values to enums - it's even done in the UT code for the ChallangeHUD, when setting Canvas.Style! So why the hell can't you assing enums to bytes?! Damn UScript.
    Damn... that sucks.

    Eater.
     
  9. Blödsinn machen

    Blödsinn machen cannon fodder

    Joined:
    Dec 4, 2001
    Messages:
    68
    Likes Received:
    0
    Canvas.Style is a byte variable, so in fact an enum value is being assigned to byte, not vice-versa. The opposite seems not to work, though (i.e. casting a byte to an enum).
    why is life so difficult...... ?
     

Share This Page