227 Compiler directives

From Oldunreal-Wiki
Revision as of 06:56, 28 September 2020 by .:..: (talk | contribs)
(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
NOTE: If Key type is an actor reference and that actor gets destroyed, it will automatically remove that key/value from the map.
227j+
Map assign or read value value «Map»[«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».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».Remove(«Key type») if( NameList.Remove('Health') ) Remove a map value (returns true if excisted) 227j+
Empty map «Map».Empty() NameList.Empty(); Empties a hash map 227j+
Map iterator foreach «Map»(«out key»,«out value»)
local name N;
local int i;
foreach NameList(N,i)
	Log(N@i);
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> «Var name»; var pointer<FMeshInstanceBase*> MeshInstance; A C++ variable to define pointer values (C++ type will directly export to header) 227j+
Arbitary variable Any var any MyProp; Can be used as a variable with any value type, also usable to pass value as a pointer. 227j+
Assign 'Any' var value SetInt/Float/Bool/Name/String/Struct/Object
MyProp.SetInt(25);
MyProp.SetFloat(25.f);
MyProp.SetString("Hello");
MyProp.SetName('World');
MyProp.SetStruct(Vector,vect(1,2,3));
MyProp.SetObject(Self);
Assign any property to a value. 227j+
Read 'Any' var value GetInt/Float/Bool/Name/String/Struct/Object
MyProp.GetInt();
MyProp.GetName();
MyProp.GetStruct(Vector);
Read any property value (WARNING: The type must match the type you are about to get, use GetType or IsType to verify it matches, Int/Float will be automatically converted between each format). 227j+
Check 'Any' type «enum EAnyPropertyType» GetType() / «struct type» GetStructType() / IsType(«var type»,«struct type»)
if( (MyProp.GetType()==ANYTYPE_Struct && MyProp.GetStructType()=='Vector') || MyProp.IsType(Struct,Vector) || MyProp.IsType(Float) )
Check what variable type is stored here. 227j+
Convert 'Any' type to string «string» GetText() / SetText(«string»)
MyProp.SetText("'Hello'");
Log(MyProp.GetText());
Export data to string or import from string. 227j+
Copy or Clone any property «any var» Copy() / Clone()
local any A,B;
A.SetText("'Hello'");
B = A.Copy();
B.Clone();
Copy will create a copy of the var data and return new pointer to it, while Clone will create a copy and replace current pointer. 227j+
Free 'any' property Release()
local any A;
A.SetText("'Hello'");
A.Release();
This will release this pointer to the data, and if no pointers remain it will free from game memory (this is done automatically when variable is destroyed). 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. Any version
Protected modifier protected var protected int Health; Makes variable constant but lets you modify value from current class. Any version
NoWarn modifier nowarn var() nowarn float VSize; Manually tell compiler to not throw a warning with variable name matching with a parent class var/function name. Any version
AutoDestruct modifier autodestruct var() editinline autodestruct DataManager DataContainer; Tells C++ codes to delete the object when destroying the Actor that references it. 227j+
Rotator constant RotAng(«Pitch»,«Yaw»,«Roll») SetRotation(rotang(0,180,0)); Same as rot but uses real angles as input (0-360 instead of 0-65536). Any version
Constant string literals \n \r \t \xHEX "Hello\r\nWorld!\xAF" Lookup escape code literals from here: http://www.cplusplus.com/doc/tutorial/constants/ Any version

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);