Gah - a solution with more questions. – EntropicLqd

Legacy:New UnrealScript In UT3

From Unreal Wiki, The Unreal Engine Documentation Site

Jump to: navigation, search

This is a list of new UnrealScript features in UT3, compared to UT2004:

Contents

[edit] Interfaces

Previously only some licensees implemented interface support in their games, but UnrealEngine 3 adds it as a default feature.

Interfaces are declared in separate .UC files, just like classes. The difference is, that they are declared using the keyword "interface" instead of "class". Interfaces don't have to extend from any other class, but if they do, the other class needs to be an interface as well.

Like in Java, you can only declare constants (not variables marked with the "const" modifier!), functions and delegates. It is currently unknown whether functions and delegates can have an implementation, but some stock interfaces declare native functions, which could be considered a kind of implementation.

[edit] Built-in Preprocessor

The UE3 Preprocessor provides a powerful macro system, similar to that provided by elmuerte's UCPP. There are a few built-in macro functions and values. For example the type of compiler run can be determined by checking if any of the macros DEBUG, RELEASE or FINAL_RELEASE are defined.

Logging is preferably done through the `log() and `warn() macro functions now. They take the message string as first parameter and an optional condition as second parameter. The message is only logged if the condition evaluates to true at runtime.

There are no instances of user-defined macro functions in the downloadable UnrealScript sources, but several instances of macro definitions for code snippets. An example is located in Object.uc:

`if(`isdefined(FINAL_RELEASE))
 	`define	prevent_direct_calls	private
 `else
 	`define	prevent_direct_calls
 `endif

it is used further down in declaration of the LogInternal and WarnInternal functions, which now should be called through the `log and `warn macros:

native(231) final static `{prevent_direct_calls}  function LogInternal( coerce string S, optional name Tag );
native(232) final static `{prevent_direct_calls}  function WarnInternal( coerce string S );

The `{macroname} syntax apparently means the macro value should be omitted from the imported source code, but still be used by the compiler. If the macro value should be inserted into the imported source code, use the `macroname syntax instead.

[edit] No More #-Directives

There's no replacement for #exec directives, you have to use UnrealEd to import resources now.

The (admittedly, very infrequently used) #include directive has been replaced by the `include() preprocessor macro.

[edit] New Default Properties Features

In addition to the defaultproperties block of the class file you can now also specify a structdefaultproperties block for every newly declared struct type. Members of a struct variable are initialized with the specified values, no matter where the struct is used.

Default dynamic array values can now be added or removed with special macros. (see New Dynamic Array Features below)

Subobjects can now be modified by subclasses. For this, the subobject needs to be redeclared in the subclass's defaults block with the same name, but without a class specification. The following is an example from PathNode changing the sprite component's texture:

defaultproperties
{
	Begin Object NAME=Sprite
		Sprite=Texture2D'EngineResources.S_Pickup'
	End Object
}

The "Sprite" object was originally defined in the NavigationPoint class:

	Begin Object Class=SpriteComponent Name=Sprite
		Sprite=Texture2D'EngineResources.S_NavP'
		HiddenGame=true
		HiddenEditor=false
		AlwaysLoadOnClient=False
		AlwaysLoadOnServer=False
	End Object
	Components.Add(Sprite)
	GoodSprite=Sprite

Note that HiddenGame, etc. are inherited by the PathNode Sprite. If these classes were in different packages and the NavigationPoint's Sprite properties were changed, all changes (except those to the Sprite property, which was overridden in PathNode's Sprite) would propagate to the PathNode Sprite without recompiling its package as well.

[edit] New Dynamic Array Features

Dynamic arrays are now a lot easier to handle, both in regular code and the default properties blocks. In UT200x dynamic arrays only had the property Length and the functions Insert and Remove and they were only available in regular code, not in the defaults section.

Now the following additional functions are available in regular code:

Add(number
Adds empty elements to the end of the array. ar.Add(x) is the same as:
ar.Length = ar.Length + x;
AddItem(value
Adds the value to the array. ar.AddItem(value) is the same as:
ar[ar.Length] = value;
RemoveItem(value
Removes all occurrences of the value from the array. For example ar.RemoveItem(none) removes all empty elements from an object array, which would otherwise require code similar to the following snippet but is likely to perform faster:
for (i = ar.length-1; i >= 0; i--)
 if (ar[i] == None)

ar.Remove(i, 1);

InsertItem(value, index
Inserts a value before the specified array element. ar.InsertItem(x, i) has the same effect as:
ar.Insert(i, 1);

ar[i] = x;

Find(value
Searches for a value and either returns the index of the first array element containing that value or -1 if the array doesn't contain the value.
Find(property name, value
A special version of Find for dynamic arrays of structs. The first parameter must be a name value matching the name of the struct member to compare to the specified value.

Additionally, every dynamic arrays automatically serves as an Iterator function. If an actual iterator function existed, its declaration would probably look similar to the following:

// The array would be declared as "array<ArrayType> ArrayName"
// NOTE: No actual code!
native iterator function ArrayName(out ArrayType Value, optional out int Index);

Note that, unlike "real" iterator functions, there's no way to limit the output to certain classes.

And finally, UnrealEngine 3 also adds dynamic array macros to defaultproperties and the new structdefaultproperties blocks. These are different from the functions available in "real" code.

Add(value
Like AddItem in real code.
Remove(value
Like RemoveItem in real code. This makes it easier to remove specific inherited values from a dynamic array without having to know the exact index.
Empty 
Removes all inherited values from the dynamic array. You don't have to add any parentheses after this one.

[edit] Metatags for Variables and Enum Elements

After the name of class and struct variables and enum elements you can now add metadata in angle brackets. Various fields are comma-separated.

Syntax:

var() usual modifiers type name<tag1=value1,tag2=value2,tag3>;

The following tags have been spotted in the UT3 UnrealScript source code:

Tooltip=text 
Displays the specified description as tooltip for the variable in UnrealEd's property window. Note that it's usually easier to use a doc comment, i.e. /** ... */, but if you already have such a comment and want to use a different text for the tooltip, you need to use the tag to override the displayed text.
DisplayName=text 
Displays the specified text instead of the variable or enum element name. Note that UnrealEd already automatically removes enum name prefixes in ALL-CAPS followed by an underscore '_' character.
EditCondition=boolean value 
(needs confirmation) Similar to the editconst variable modifier, but applied dynamically based on the specified condition.
All occurrences in stock code refer to bool variables at the same scope, i.e. for class variables it's a bool variable in the same class and for struct members it's a bool-type member in the same struct.
AllowAbstract 
For variables of type Class this tag allows the user to select abstract classes. Without the tag, only non-abstract classes can be selected from the drop-down list. Always use this tag if you don't intend to create instances of the specified class. For for example it is absolutely essential to use this class for DamageTypes or LocalMessages, since those classes are always abstract.
AutoComment=true 
Apparently this tag only works in SequenceObject classes and also only if the class's bSuppressAutoComment property is set to false. The effect of this tag seems to be that the tagged variable's value is displayed in the sequence object's comment in the Kismet editor.
Personal tools