Announcement

Collapse
No announcement yet.

Accessing enum from another class

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Accessing enum from another class

    I have the following problem:

    I declared an enum in another class:

    Code:
    class Test1 extends KAssetSpawnable;
    
    	enum E_Color
    	{
    		COLOR_Red,
    		COLOR_Green,
    		COLOR_Blue,
    		COLOR_Yellow,
    		COLOR_Magenta,
    		COLOR_Cyan,
    		COLOR_White,
    		COLOR_Black
    	};
    I now want a variable of the type E_Color in a second class:

    Code:
    class SpeedPowerUp extends PowerUp
    	placeable;
    
    var MaterialInstanceConstant powerUpColor1;
    var E_Color powerUpColor;
    
    
    function setColor(){
    	local byte xcolor;
    	local LinearColor vcolor;
    	powerUpColor1 = new Class'MaterialInstanceConstant';
    	powerUpColor1.setParent(Material'PowerUps.Materials.Mat_PowerUp_Color_Glow');
    	xcolor = Rand(3);
    
    	if(xcolor == 0){
    		vcolor.R = 10;
    		powerUpColor1.SetVectorParameterValue('Color',vcolor);
    		powerUpColor = E_Color.COLOR_Red;  //<----------------- Heres the Error
    	}
    But the compiler gives me the following error:
    Bad or missing expression for token: E_Color, in '=' in line 19
    I've googled a bit and I tried dependson(Test1) and Test1.E_Color.COLOR_Red but it still wont work...

    Any suggestions?

    #2
    If both classes are in the same package, add dependson(Test1) to the class declaration of SpeedPowerUp to make sure it is parsed after the enum declaration is known.

    Comment


      #3
      Also:
      Code:
      powerUpColor = COLOR_Red;

      Comment


        #4
        Originally posted by RattleSN4K3 View Post
        Also:
        Code:
        powerUpColor = COLOR_Red;
        ^this + dependson worked! I am still wondering why I don't have to add E_Color. to the statement. It feels a bit wrong.
        Maybe its because I'm a Java Programmer xD

        Comment


          #5
          You don't have to add it because when an expression is evaluated in an "enum context", the compiler knows what you want to do. Java enum values are objects (instances of the enum class) and you essentially access them though static fields of the enum class. UnrealScript enums are something completely different in that regard, because they are "glorified byte values", much like C++ enums are glorified int values.

          Comment

          Working...
          X