Sharing enumerations

  • 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.

pkooman

New Member
Jun 30, 2004
6
0
0
Hi,

I was wondering whether I could use an enumeration which is defined in another class. I want to define an item to pickup and use an enumeration to specify it:

Code:
class ItemPickup extends Pickup;

// Possible Items
enum ItemType {
    ItemA,
    ItemB
};

// Editable from Properties Screen
var () ItemType itemType;

defaultproperties {
    itemType=ItemA
    InventoryType=Game.Item
    DrawType=DT_StaticMesh
}

Now I'd like to use this enum in my inventory class, and be able to say:

Code:
class Item extends Inventory;

// Item type from ItemPickup
// ** DOES NOT COMPILE, but I'd like to do something like this. **
var ItemPickup.ItemType itemType;

function bool HandlePickupQuery( pickup Item ) {
        if ( class == item.InventoryType ) {                
                // Copy the value here.
		itemType = (ItemPickup(item).itemType);
		return true;				
	}

	return Inventory.HandlePickupQuery(Item);
}

But I can't come up with a way to 'share' the enum type. Has it something todo with .int and .ucl files maybe?

Thanks in advance.
 

Bonehed316

New Member
Oct 15, 2001
208
0
0
41
Florida
Visit site
enums are just a set of bytes with a friendly name, so you can really just create the exact enum in a different class, and they will work together without a problem. that is how enums can also work with certain operators.
 

[SAS]Solid Snake

New Member
Jun 7, 2002
2,633
0
0
40
New Zealand
www.digitalconfectioners.com
It depends how far you go in terms of designing your code layout. I used to be the type that just coded whatever that came to my head, but after a while it became annoying form e having to go through a lot of my old code to clean it up or to rewrite it due to changing methods. Usually now I plan a lot of the methods I want to do things in and then code from there. But that of course makes me difficult when it comes to working with other coders.
 

Techno JF

He Who Has Powerful Words
Excellent information here. I may find this thread of use to me later.

I have a question for you, Solid Snake. Do you know if this DependsOn syntax works in version 436? Or do I have to write an orphaned function in the second class with a command to spawn an instance of the first class, in order to force UCC to compile the classes in the proper order?
 
Last edited:

BinarySystem

Banned
Jun 10, 2004
705
0
0
UCC seems to be able to access members, etc. of other classes regardless of the order in which they are compiled, so long as they are in the same package. I've never had any issue with that. Also, you can have two classes that use dependson for each other - so I think dependson does something other than just tweak the order in which the classes in a package are compiled.

I think what you are looking for is "qualifying" an enum, as described in the Unrealscript language reference by Tim Sweeney.
http://unreal.epicgames.com/UnrealScript.htm

I think this information is on the wiki too, but I couldn't find it, so maybe it isn't.
 

Techno JF

He Who Has Powerful Words
Ah yes, it makes sense. From Actor.uc:

Code:
00113	// Scriptable.
00114	var       const LevelInfo Level;         // Level this actor is on.
00115	var transient const Level XLevel;        // Level object.
00116	var(Events) name		  Tag;			 // Actor's tag name.
00117	var(Events) name          Event;         // The event this actor causes.
00118	var Actor                 Target;        // Actor we're aiming at (other uses as well).
00119	var Pawn                  Instigator;    // Pawn responsible for damage.
00120	var(Sound) sound        AmbientSound;    // Ambient sound effect.
00121	var Inventory             Inventory;     // Inventory chain.
00122	var const Actor           Base;          // Moving brush actor we're standing on.
00123	var const PointRegion     Region;        // Region this actor is in.
00124	var(Movement)	name	  AttachTag;

This block of code contains pointers to LevelInfo, Pawn, and Inventory actors. All of these classes are also defined in Engine.u along with Actor, but Actor has to be compiled first because it's a superclass to all of them. On the other hand, these pointers still don't cause any errors as long as the classes they refer to don't exist in other packages.
 

Bonehed316

New Member
Oct 15, 2001
208
0
0
41
Florida
Visit site
i imagine he was trying to do something where he either didnt want the variables to change, or wanted the default value, both of which are possible through other methods.
 

dataangel

New Member
Apr 11, 2004
184
0
0
I meant declare enum's static -- as in static enumerated types, not individual instances of them. Peppers vs. pepper grinders ;)

This way you could share an enumeration between classes, like asked for in the post.
 
Last edited:

Hunz

...aka [A|K]Leviathan, mkay?
Jan 7, 2002
302
0
0
Jail
www.arschkeKse.de.vu
Here something I found today while surfing code (just an example):
Code:
var hudbase.escalemode blabla;

This variable-definition can be placed in any class, although the enumeration 'escalemode' is only defined in the class 'hudbase' looking like that:
Code:
enum EScaleMode
{
    SM_None,
    SM_Up,
    SM_Down,
    SM_Left,
    SM_Right
};

...looks pretty much like sharing (or at least borrowing) enumerations :)