Results 1 to 11 of 11
  1. #1

    Default "Global Enumerations"

    Disclaimer: First encounter with UnrealScript =noob=

    I was making initial scripts for a simple thing I want to do, that is to create a character select screen ala fighting game. Normally, in C++ i would do a fixed enumeration of the IDs of the characters on a file like:
    Code:
    enum eCharacters
    {
        eC_Ryu,
        eC_Ken,
        eC_Guile,
        eC_Chunli,
        eC_Num
    };
    Now I have two classes that would like to re-use this enumeration. One is HUD_CharacterSelect and Character. How can I re-use this enumeration without redefining on the two classes?

    HUD_CharacterSelect.uc
    Code:
    class HUD_CharacterSelect extends HUD;
    
    var eCharacters Player1;
    and

    Character.uc
    Code:
    class Character extends Pawn;
    
    var eCharacters Id;
    Compiling results: Unidentified type eCharacters on both sources.

    I've also tried putting the enum on a single class called Constants.uc but didn't work
    Code:
    class Constants extends Object;
    
    enum eCharacters
    {
        eC_Ryu,
        eC_Ken,
        eC_Guile,
        eC_Chunli,
        eC_Num
    };
    What's the proper way to do this?

  2. #2
    Redeemer
    Join Date
    Nov 2007
    Posts
    1,207

    Default

    All enums must be in a class. So your last example should be the correct one. I'm unsure why that one isn't working.
    Nightblade, a stealth based total conversion for UT3

  3. #3
    MSgt. Shooter Person
    Join Date
    Oct 2007
    Posts
    167

    Default

    i would say using dependson is the proper way,

    class HUD_CharacterSelect extends HUD
    dependson(Character);

    And then defining the enum in Character

  4. #4

    Default

    The depenson() class modifier ensures the depended class is parsed first, so all enum and struct declarations are already known when the depending class that uses the enum/struct type name in a declaration is parsed.
    Wormbo's UT/UT2004/UT3 mods | PlanetJailbreak | Unreal Wiki | Liandri Archives

    <@Mych|Lockdown> ...and the award for the most creative spelling of "Jailbreak" goes to ... "Gandis Jealbrake Server"
    Note that your questions via PMs will be ignored if they actually belong in the forum.

  5. #5

    Default

    @immortius, @Sarcen, @Wormbo: Thanks all guys! DependsOn is what I needed.

  6. #6
    MSgt. Shooter Person
    Join Date
    Jun 2011
    Posts
    53

    Default

    Above suggestions do not work for me (VS2010 + nFringe).

    Could it be that I'm calling a static method? I also tried for the 'severity' parameter to be required with same results.

    Actual error: Call to 'Log': bad or missing parameter 2

    Sample call that fails: class'Phan_Logger'.static.Log("Target Loc: " @Target.Location.X @", " @Target.Location.Y, EnumLogSeverity.ELS_Debug2);

    Code:
    class Phan_Logger extends Object
    	NotPlaceable;
    
    // about enums: http://wiki.beyondunreal.com/Enums
    enum EnumLogSeverity
    {
    	ELS_Emergency,
    	ELS_Alert,
    	ELS_Critical,
    	ELS_Error,
    	ELS_Warning,
    	ELS_Notice,
    	ELS_Information,
    	ELS_Debug,
    	ELS_Debug2,
    	ELS_Debug3
    };
    
    // since the Log method is static the verbosity var can not be set but its default value can be obtained
    var(Phantasm) const editconst EnumLogSeverity LoggingVerbosity;
    
    // Logs message
    static function Log(string msg, optional EnumLogSeverity severity = EnumLogSeverity.ELS_Debug)
    {
    	if ( severity >  default.LoggingVerbosity ) return;
    
    	switch( severity )
        {
          default: 
          	`log("##PHAN## " @msg);
          	break;
        }
    
    	return;
    }
    
    
    DefaultProperties
    {
    	//Set log verbosity here
    	LoggingVerbosity = EnumLogSeverity.Debug;
    }
    Last edited by fixitchris; 08-26-2011 at 10:08 PM.

  7. #7
    Veteran
    Join Date
    May 2007
    Location
    Above KillZ, Below StallZ
    Posts
    9,986

    Default

    I -think- you can also do var class'Whatever'.eCharacters character; but .. not entirely positive at the moment. I always just make sure that it's in something that is compiled first.
    http://www.ericbla.de http://www.dungeondefenders.com http://en.wikipedia.org/wiki/Warm_Gun http://www.rekoil.com http://www.groundbranch.com

    - Please don't send me private messages asking programming questions, those would be better asked on the Programming forum here. Thanks

  8. #8
    MSgt. Shooter Person
    Join Date
    Jun 2011
    Posts
    53

    Default

    That doesn't work either. I thought that dependson() directs classes to compile before others...

    as a workaround, passing the integer value of the enum works.

  9. #9

  10. #10
    MSgt. Shooter Person
    Join Date
    Jun 2011
    Posts
    53

    Default

    Thanks that worked.

    I also took DependsOn(Phan_Logger) out of the log client and it still compiled.

  11. #11

    Default

    You only need DependsOn() if you want to use the type (struct or enum) itself. If you need a value of the type to call a function or assign a variable, DependsOn() is not required because at that time the declaration is already known. You also don't need to qualify the enum value there because you have no other choice anyway. (Well, you have, but common sense tells you should be putting a value of the required enum type there.)
    Wormbo's UT/UT2004/UT3 mods | PlanetJailbreak | Unreal Wiki | Liandri Archives

    <@Mych|Lockdown> ...and the award for the most creative spelling of "Jailbreak" goes to ... "Gandis Jealbrake Server"
    Note that your questions via PMs will be ignored if they actually belong in the forum.


 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright ©2009-2011 Epic Games, Inc. All Rights Reserved.
Digital Point modules: Sphinx-based search vBulletin skin by CompletevB.com.