ZScript special words
Jump to navigation
Jump to search
Note: This feature is for ZScript only. |
ZScript contains special words for certain circumstances.
- is
- Compares a pointer or class type to a class type. This will also return true if the given pointer or class type is a child of the class type it's comparing to.
if (mobj is "ClassName") if ("ClassC" is "ClassA")
- let
- Infer the type of a local variable from what is initially assigned to it.
let a = 1; // The type of a is int. let b = self.Owner; // The type of b is Actor. let c = 1.25; // The type of c is double. let d = "Hello, world!"; // The type of d is String. let e = FindInventory(...); // The type of e is Inventory. let [f, g] = A_SpawnItemEx(...); // The types of f and g are bool and Actor, respectively.
- You can use this as a shorthand for checking the real class of an object:
let i = Inventory(someObject);
// The type of i is Inventory.
// If someObject is an instance of Inventory, then i will refer to that object.
// If someObject is of some other class, then i will be null.
- out
- Qualifier for function parameters. Allows passing of a parameter by reference.
void MyFunction(out MyStruct s)
{
s.value = 5; // this can be used to modify a struct directly since they can't be returned
}
- &
- Works the same as the out keyword, but looks more like how parameters are passed by reference in C++.
void PassByRefFun (array <Actor> &ArrayName)
- dot
- Calculates the dot product of two vectors, resulting in a double. The syntax can take either a Vector2 or Vector3, but they must be the same on both sides. It is equivalent to a.length() * b.length() * cos(angle), where angle is the angle between the two vectors. A result of 0 means the vectors are orthogonal, or 90 degrees.
- For example, if using two unit vectors and the result is -1, the vectors are turned 180 degrees, meaning they're pointed in opposite directions. 1 means they're parallel.
- <Vector2> dot <Vector2>
- <Vector3> dot <Vector3>
- cross
- Calculates the cross product of two Vector3s, resulting in a Vector3. The return value is a new vector that is perpendicular to both of the inputs (unless one of them is a 0 vector, or they are parallel/antiparallel), and therefore it cannot be used on 2D vectors.
- <Vector3> = <Vector3> cross <Vector3>
Vector3 a = (1, 2, 3); Vector3 b = (3, 2, 1); double dot_prod = a dot b; Vector3 cross_prod = a cross b;
- self
- Used to reference the world actor currently running ZScript code. Typically implied, but sometimes useful to specify, such as when a variable in a function has the same name as a variable in the class. In such cases, self will refer to the variable in the actor instead of the function when appended with self.
- invoker
- Only used in functions that have the action keyword. Used to reference the actor that owns the State the function is currently being called from. This can be used to directly modify any variables on the true caller e.g. the weapon the player is currently using as opposed to the player themselves.