227 Compiler directives

From Oldunreal-Wiki
Revision as of 10:20, 14 July 2020 by .:..: (talk | contribs) (Created page with "== 227 Compiler directives == Here is a complete list of new compiler directives and script functionality (can only be compiled with 227j+ compiler). {| class="wikitable" |-...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

227 Compiler directives

Here is a complete list of new compiler directives and script functionality (can only be compiled with 227j+ compiler).

Name Code syntax Example Description Compatibility (compiled code)
Ternary operator «Bool condition» ? «Value if True» : «Value if false» Health -= (Armor.Charge>10) ? 0 : (Damage*0.5); Can be used to inline an if condition with a simple action 227i+
Static cast value TypeCast<«Variable type»>(«Value») TypeCast<float>(Health) Will cast a variable from one type to another without conversion. Any version
Get array size int «const Dynamic array».Size() Actor.RealTouching.Size() Grab a dynamic array size 227c+
Set array size int «Dynamic array».SetSize(«New size») MyArray.SetSize(25) Change dynamic array size and return the new size value 227c+
Insert array bool «Dynamic array».Insert(«Offset»,«optional count=1») MyArray.Insert(5,1) Insert a new element into a dynamic array 227c+
Remove array bool «Dynamic array».Remove(«Offset»,«optional count=1») MyArray.Remove(5,1) Remove an element from a dynamic array 227c+
Empty array bool «Dynamic array».Empty() MyArray.Empty() Empties a dynamic array 227c+
Add item int «Dynamic array».Add(«Value») MyArray.Add(Class'Pawn') Append a new element with a new value to array (returns index of the new value) 227j+
Add unique item int «Dynamic array».AddUnique(«Value») MyArray.AddUnique(Class'Pawn') Add a new value to array if not already in it (returns index of said value) 227j+
Remove item bool «Dynamic array».RemoveValue(«Value») MyArray.RemoveValue(Class'Pawn') Find and remove a single entry from a dynamic array (returns true if found and removed value) 227j+
Find item int «Dynamic array».Find(«Value»,«optional Struct member») int i = MyArray.Find(25.f,X) Find a value from a dynamic array (or with a specific struct element value) 227j+
Array iterator foreach «Dynamic array»(«out Value»,«optional out int index») foreach MyArray(MyValue,ValueIndex) Iterate through every array element 227j+
Hashed variable map Map<«Key type»,«Value type»> var map<name,int> NameList; Can be used as a fast lookup pair map 227j+
Map assign or read value value Map<«Key type»,«Value type»>[«Key type»] NameList['Health'] = 25; Access and read value by key (NOTE: If looking up and value is not found, it will create one) 227j+
Map lookup value bool Map<«Key type»,«Value type»>.Has(«Key type»,«optional out Value type») if( NameList.Has('Health',CurValue) ) Look up if a key value excists 227j+
Remove map value bool Map<«Key type»,«Value type»>.Remove(«Key type») if( NameList.Remove('Health') ) Remove a map value (returns true if excisted) 227j+
Empty map Map<«Key type»,«Value type»>.Empty() NameList.Empty(); Empties a hash map 227j+
Map iterator foreach Map<«Key type»,«Value type»>(«out key»,«out value») foreach NameList(MyName,MyInt) ) Iterate through every map value 227j+
Button property Button<«Description string or name»> «Var name»;
var Button<"Delete this actor"> DeleteButton;

function OnPropertyChange( name Property, name ParentProperty )
{
	if( Property=='DeleteButton' ) Destroy(Self);
}
A variable thats hidden in code but visible in properties window as a button, will output button press in Object.OnPropertyChange/Object.StaticPropertyChange 227j+
Pointer property Pointer<C++ type&gt «Var name»; var pointer<FMeshInstanceBase*> MeshInstance; A C++ variable to define pointer values (C++ type will directly export to header) 227j+
C++ class extension extends class Subsystem extends Object extends FExec native abstract; A C++ secondary class extension (not visible in UnrealScript, exports to header) 227j+
C++ header text cpptext{«code»}
cpptext
{
	UMyClass() {}
}
struct export MyStruct
{
	var int A;
	cpptext
	{
		int GetA() const
		{
			return A;
		}
	}
};
Export C++ text to header Any version
C++ struct header export struct export «struct name»
struct export TheStruct
{
	var int A;
};
Export UnrealScript struct declaration to C++ header Any version
C++ struct replication struct nativereplication «struct name»
struct nativereplication PackedInt
{
	var() config int Value;
	var const int MaxValue;
};
Tell C++ codes to bind struct to a native replication method for struct networking (see below for example) 227j+
Size of object sizeof(«struct name»)
struct export ActorBuffer
{
	var byte Padding[sizeof(Actor)];
};
A constant int for object size Any version
Preprocessed maths {«math op»} Vector.X = Sin({Pii / 4.0}); Will compute math operations during compile time and build in the resulted value directly in code (you can use any math operators or access any UScript constants or default values of parent packages). Any version
Defaultproperties maths «Variable»=«math op»
defaultproperties
{
	Health=Nali.Health+25
}
Same as preprocessed maths but for defaultproperties (only works with byte/int/float variables). Any version
Custom compiler order DependsOn(«classname») class RenderIterator expands Object native DependsOn(Actor) transient; Tell UnrealScript compiler to parse and compile another class first. Any version
Object within Within «classname» class MyExtension expands Object within PlayerPawn; Tell UnrealScript compiler to lookup for variable values or functions from another class, requires you to construct the object in-game with said class as outer (See CheatManager or Admin in UnrealEngine 2). 227j+
EditInLine modifier editinline var() editinline PortalModifier PortalModifier; Lets you create a new object reference in properties window and tells C++ codes to duplicate the object when instancing that object in game. 227j+
AutoDestruct modifier autodestruct var() editinline autodestruct DataManager DataContainer; Tells C++ codes to delete the object when destroying the Actor that references it. 227j+

Sample of struct nativereplication

Heres a sample of what to write in Cpp code file when writing nativereplication for packedint struct.

void SerializePackedInt(FArchive& Ar, UPackageMap* Map, FPackedInt* Data)
{
	if (Data->MaxValue<=0)
		return;
	DWORD Value = Clamp(Data->Value, 0, Data->MaxValue);
	Ar.SerializeInt(Value, Data->MaxValue + 1);
	if (Ar.IsLoading())
		Data->Value = Value;
}
IMPLEMENT_STRUCT_REP(packedint, SerializePackedInt);