* [Examples: Member declarations](#examples-member-declarations)
2018-10-12 16:50:04 -07:00
<!-- vim-markdown-toc -->
Introduction
============
ZScript is a new (circa 2017) scripting language that has sprung from the ceasing of ZDoom and the subsequent reprisal of GZDoom as mainline. It is similar to Java, though it has many deficiencies, oddities and other such issues. Despite this, it is still the most powerful Doom modding tool since straight up source editing, and will likely stay that way for a while until Eternity Engine inevitably becomes competition-worthy with scripting additions.
This documentation serves as an introduction to and informal specification of the ZScript language from a programmer's viewpoint. It should also be useful for non-programmers looking for specifics on the inner workings of the language and more information on the functions and properties provided to it.
ZScript runs in a virtual machine much like ACS, although because it is *not* compiled to bytecode and uses an object-oriented structure, the virtual machine is far more complex, and also therefore quite a bit slower. ZScript may only be read from source files by the engine, which has several benefits as well as detriments. It is the opinion of the author that this is a bad solution, but the author will refrain from going on a several-paragraph tirade about why bytecode is always better than source, even if it is an optional component.
In any case, here we are. This documentation will detail all aspects of ZScript, from the language and type system to the API and finer details. This document is distributed under the [CC0 public domain license](https://creativecommons.org/publicdomain/zero/1.0/legalcode) in the hope that it is useful reference and serves as a solid basis for further writings. This document was originally written by Alison Sanderson (Marrub.) Attribution is encouraged but not required.
2018-11-14 13:14:27 -08:00
Language
========
2018-10-12 16:50:04 -07:00
Translation Unit
2018-11-14 13:14:27 -08:00
----------------
2018-10-12 16:50:04 -07:00
Full ZScript files are referred to as "translation units." This terminology comes from the C standard, and refers simply to the entirety of a ZScript source file. ZScript files are looked for in lumps named `zscript` with any extension. The standard extension is `.txt`, but `.zsc` and `.zs` are common as well. The author of this documentation prefers `.zsc`.
The base translation unit `zscript` may start with a version directive, then followed by any number of top-level definitions and `#include` directives. Included translation units may not have version directives.
All keywords and identifiers in ZScript are case insensitive.
2018-02-07 06:27:22 -08:00
2018-10-10 13:55:53 -07:00
Versions
2018-11-14 13:14:27 -08:00
--------
2018-10-10 13:55:53 -07:00
A version directive may be placed at the very beginning of a ZScript file, the syntax being:
```
version "num"
```
2018-11-14 13:14:27 -08:00
Where `num` is the ZScript version to use. By default ZScript is `version "2.3"`, the original ZScript specification. This old version is not supported by this documentation and it is highly encouraged to always use the latest version of ZScript. The minimum version supported by this documentation is 3.0.
2018-10-10 13:55:53 -07:00
Here is a list of differences between ZScript versions:
2018-11-14 13:14:27 -08:00
Version 3.1
- Added `UserCmd`.
- Added `PlayerPawn::CROUCHSPEED`.
- Added `PlayerPawn::TURN180_TICKS`.
- Added `PlayerPawn::FireWeapon`.
- Added `PlayerPawn::FireWeaponAlt`.
- Added `PlayerPawn::CheckWeaponFire`.
- Added `PlayerPawn::CheckWeaponChange`.
- Added `PlayerPawn::TickPSprites`.
- Added `PlayerPawn::DeathThink`.
- Added `PlayerPawn::CheckFOV`.
- Added `PlayerPawn::CheckCheats`.
- Added `PlayerPawn::CheckFrozen`.
- Added `PlayerPawn::CrouchMove`.
- Added `PlayerPawn::CheckCrouch`.
- Added `PlayerPawn::ForwardThrust`.
- Added `PlayerPawn::Bob`.
- Added `PlayerPawn::TweakSpeeds`.
- Added `PlayerPawn::MovePlayer`.
- Added `PlayerPawn::CheckPitch`.
- Added `PlayerPawn::CheckJump`.
- Added `PlayerPawn::CheckMoveUpDown`.
- Added `PlayerPawn::HandleMovement`.
- Added `PlayerPawn::CheckUndoMorph`.
- Added `PlayerPawn::CheckPoison`.
- Added `PlayerPawn::CheckDegeneration`.
- Added `PlayerPawn::CheckAirSupply`.
- Added `PlayerPawn::PlayerThink`.
- Added `PlayerPawn::CheckMusicChange`.
- Added `PlayerPawn::CalcHeight`.
- Added `PlayerPawn::CheckEnvironment`.
- Added `PlayerPawn::CheckUse`.
- Added `PlayerPawn::CheckWeaponButtons`.
- Added `PlayerPawn::BestWeapon`.
- Added `PlayerInfo::Cmd`.
- Added `PlayerInfo::Original_Cmd`.
- Added `PlayerInfo::IsTotallyFrozen`.
- Added `PlayerInfo::Uncrouch`.
- Added `ListMenuItemSlider::mDrawX`.
- Added `SBarInfo::GetProtrusion`.
- Added `Actor::ORIG_FRICTION`.
- Added `Actor::ORIG_FRICTION_FACTOR`.
- Added `Actor::CheckFakeFloorTriggers`.
- Added `global LocalViewPitch`.
- Added `LevelLocals::AllowRespawn`.
- Added `LevelLocals::IsJumpingAllowed`.
- Added `LevelLocals::IsCrouchingAllowed`.
- Added `LevelLocals::IsFreelookAllowed`.
- Added `LAF_OVERRIDEZ`.
- Added `HarmonyStatusBar`.
- Added `SVELight`.
- Added `SVEFlagSpot*`.
- Added override for `DoomStatusBar::DrawAutomapHUD`.
- Added override for `SBarInfoWrapper::GetProtrusion`.
- Added `offsetz` parameter to `Actor::LineAttack`.
- Made `PlayerInfo::Cls` not `readonly`.
Version 3.2
- Added `+ZDOOMTRANS`.
- Added `+DYNAMICLIGHT.ADDITIVE`.
- Added `+DYNAMICLIGHT.SUBTRACTIVE`.
- Added `+DYNAMICLIGHT.ATTENUATE`.
- Added `FCheckPosition::PortalGroup`.
- Added `Actor::FloatBobStrength`.
- Added `Actor::CameraFOV`.
- Added `Actor::RenderHidden`.
- Added `Actor::RenderRequired`.
- Added `Actor::CheckPortalTransition`.
- Added `Actor::A_SoundVolume`.
- Added `Font::CR_ICE`.
- Added `Font::CR_FIRE`.
- Added `Font::CR_SAPPHIRE`.
- Added `Font::CR_TEAL`.
- Added `Font::TEXTCOLOR_ICE`.
- Added `Font::TEXTCOLOR_FIRE`.
- Added `Font::TEXTCOLOR_SAPPHIRE`.
- Added `Font::TEXTCOLOR_TEAL`.
- Added `Thinker::STAT_USER`.
- Added `Thinker::STAT_USER_MAX`.
- Added `DropItem::Amount`.
- Added `LevelLocals::GiveSecret`.
- Added `String::IndexOf`.
- Added `String::LastIndexOf`.
- Added `String::ToUpper`.
- Added `String::ToLower`.
- Added `String::ToInt`.
- Added `String::ToDouble`.
- Added `Shader`.
- Added `TEXTCOLOR_ICE`.
- Added `TEXTCOLOR_FIRE`.
- Added `TEXTCOLOR_SAPPHIRE`.
- Added `TEXTCOLOR_TEAL`.
- Added `ActorRenderFeatureFlag`.
- Fixed `BlockLinesIterator::Create*` returning the wrong type.
- Changed `Screen::SetCameraToTexture`'s `fov` parameter to `double`.
Version 3.2.1
- Added `GameInfoStruct::mSliderColor`.
Version 3.2.2
- Added `PlayerPawn::GetClassicFlight`.
- Added `Actor::Warp`.
- Added `TexMan::GetName`.
- Added `CVar::GetBool`.
- Added `CVar::SetBool`.
- Added `Wads::CheckNumForFullName`.
- Added `Wads::FindLump`.
- Added `Wads::ReadLump`.
- Added `Wads::FindLumpNamespace`.
- Added `String::Remove`.
- Added `String::Split`.
- Added `LAF_TARGETISSOURCE`.
- Added `LAF_ABSOFFSET`.
- Added `LAF_ABSPOSITION`.
- Added `EmptyTokenType`.
- Added `offsetforward` and `offsetside` parameters for `Actor::LineAttack`.
- Added `endIndex` parameter for `String::LastIndexOf`.
- Made `Array::Find` be `const`.
- Made `Array::Max` be `const`.
Version 3.2.3
- Made `Ceiling::CreateCeiling` be `static`.
Version 3.2.4
- Added `DMG_NO_PAIN`.
Version 3.2.5
- Added `Actor::CheckMove`.
- Added `Screen::DrawLine`.
- Added `LevelLocals::PixelStretch`.
- Added `LevelLocals::Vec2Diff`.
- Added `LevelLocals::Vec3Diff`.
- Added `ECheckMoveFlags`.
- Added `SKILLP_PlayerRespawn`.
- Added `alpha2` parameter to `Actor::A_SetBlend`.
- Changed `Thinker::Tics2Seconds`' logic.
2018-10-10 13:55:53 -07:00
Version 3.3
- Default parameters in overridden virtual functions are now an error.
- Renamed `DynamicLight::ELightType::SpotLight` to `DummyLight`.
- Made `Side::V1` be `clearscope`.
- Made `Side::V2` be `clearscope`.
- Made `SecPlane::ZatPoint` be `clearscope`.
- Made `SecPlane::HeightDiff` be `const`.
- Made `Weapon::CheckAmmo` and `Weapon::DepleteAmmo` be `virtual`.
Version 3.3.1
- Made `A_SetSize`'s `radius` parameter have a default.
- Made all `DehInfo` members `readonly`.
- Made all `State` members `readonly`.
- Made `Side::Sector` and `Side::Linedef` be `readonly`.
Version 3.3.2
- Added `SPAC`.
- Added `Line::Activate`.
- Added `Line::RemoteActivate`.
2018-10-10 13:55:53 -07:00
Version 3.4
2018-11-14 13:14:27 -08:00
- Added `Actor::OnGiveSecret`.
- Added `LevelLocals::Vec2Offset`.
- Added `LevelLocals::Vec2OffsetZ`.
- Added `LevelLocals::Vec3Offset`.
- Added `WorldEvent::ActivationType`.
- Added `Line::ESide`.
- Added `DTA_Desaturate`.
- Added `DTA_Color`.
- Added `DTA_FlipY`.
- Added `DTA_SrcX`.
- Added `DTA_SrcY`.
- Added `DTA_SrcWidth`.
- Added `DTA_SrcHeight`.
- Added "`internal`" keyword.
- Made `LevelLocals::SectorPortals` be `internal`.
- Made `Sector::Portals` be `internal`.
- Changed `PlayerPawn::ResetAirSupply`'s `playgasp` default to `true`.
Version 3.5
- Added `Menu::SetVideoMode`.
- Added `DTA_LegacyRenderStyle`.
- Added `Shape2D`.
- Added `Screen::DrawShape`.
- Added `MeansOfDeath` parameter to `Actor::Die`.
- Replaced `ListMenuItemPlayerDisplay::mTranslation` with `mBaseColor` and `mAddColor`.
2018-10-10 13:55:53 -07:00
2018-10-12 16:50:04 -07:00
Version 3.5.1
2018-11-14 13:14:27 -08:00
- Added `String::RightIndexOf`.
- Made `Actor::DeltaAngle` be `clearscope`.
- Made `Actor::AbsAngle` be `clearscope`.
- Made `Actor::AngleToVector` be `clearscope`.
- Made `Actor::RotateVector` be `clearscope`.
- Made `Actor::Normalize180` be `clearscope`.
- Made `Actor::BobSin` be `clearscope`.
- Made `Actor::GetDefaultSpeed` be `clearscope`.
- Made `Actor::FindState` be `clearscope`.
- Made `Actor::GetDropItems` be `clearscope`.
- Deprecated `String::LastIndexOf`.
Version 3.6
- Added `Inventory::OnDrop`.
- Added `GLTextureGLOptions`.
- Added `Actor::A_CheckForResurrection`.
- Added `Actor::A_RaiseSelf`.
- Added `Actor::CanRaise`.
- Added `Actor::Revive`.
- Added `Screen::DrawThickLine`.
- Added `LevelLocals::SphericalCoords`.
- Added `StaticEventHandler::CheckReplacement`.
- Added `StaticEventHandler::NewGame`.
- Added `DMG_EXPLOSION`.
- Added `TRF_SOLIDACTORS`, `TRF_BLOCKUSE`, and `TRF_BLOCKSELF`.
- Made `StatusScreen::End` be `virtual`.
2018-10-12 16:50:04 -07:00
2018-02-07 06:25:22 -08:00
Top-level
2018-11-14 13:14:27 -08:00
---------
2018-02-07 06:25:22 -08:00
2018-10-10 13:55:53 -07:00
A ZScript file can have one of several things at the top level of the file, following a version directive:
2018-02-07 06:25:22 -08:00
- Class definitions
- Structure definitions
- Enumeration definitions
- Constant definitions
- Include directives
Class definitions
2018-11-14 13:14:27 -08:00
-----------------
2018-02-07 06:25:22 -08:00
A class defines an object type within ZScript, and is most of what you'll be creating within the language.
2018-02-07 07:03:25 -08:00
All classes inherit from other classes. The base class can be set within the class header, but if it is not the class will automatically inherit from Object.
2018-02-07 06:25:22 -08:00
2018-02-08 02:54:33 -08:00
Classes are subject to Scoping. They are also implicitly reference values, and therefore can be null. Use `new` to instantiate a new class object.
2018-02-07 06:25:22 -08:00
2018-11-14 13:14:27 -08:00
Classes that inherit from Actor can replace other actors when spawned in maps, and can also be used freely in `DECORATE`. Actors have states, which will not be explained in this document as they are already well-documented on the ZDoom wiki.
2018-02-07 08:24:37 -08:00
2018-02-07 07:03:25 -08:00
A class is formed with the syntax:
2018-02-07 06:25:22 -08:00
2018-02-07 07:03:25 -08:00
```
class Name [: BaseClass] [Class flags...]
{
[Class content...]
}
```
2018-02-07 06:25:22 -08:00
2018-02-07 07:03:25 -08:00
Or, alternatively, the rest of the file can be used as class content. Note that with this syntax you cannot use include directives afterward:
2018-02-07 06:25:22 -08:00
```
2018-02-07 07:03:25 -08:00
class Name [: BaseClass] [Class flags...];
[Class content...]
2018-02-07 06:25:22 -08:00
```
2018-02-08 06:50:19 -08:00
If the class is defined within the same archive as the current file, then one can continue a class definition with the syntax:
```
extend class Name
```
In place of the class header.
2018-11-14 13:14:27 -08:00
### Class flags
2018-02-07 06:25:22 -08:00
2018-02-28 13:54:44 -08:00
| Flag | Description |
2018-10-12 16:50:04 -07:00
| ---- | ----------- |
2018-02-28 13:54:44 -08:00
| `abstract` | Cannot be instantiated with `new`. |
2018-11-14 13:14:27 -08:00
| `native` | Class is from the engine. Only usable internally. |
2018-02-28 13:54:44 -08:00
| `play` | Class has Play scope. |
2018-02-07 08:24:37 -08:00
| `replaces ReplaceClass` | Replaces ReplaceClass with this class. Only works with descendants of Actor. |
2018-11-14 13:14:27 -08:00
| `ui` | Class has UI scope. |
2018-02-28 13:54:44 -08:00
| `version("ver")` | Restricted to ZScript version *ver* or higher. |
2018-02-07 06:25:22 -08:00
2018-11-14 13:14:27 -08:00
### Class content
2018-02-08 05:00:46 -08:00
Class contents are an optional list of various things logically contained within the class, including:
- Member declarations
- Method definitions
- Property definitions
- Default blocks
- State definitions
- Enumeration definitions
- Structure definitions
- Constant definitions
- Static array definitions
2018-11-14 13:14:27 -08:00
### Property definitions
2018-02-08 05:00:46 -08:00
Property definitions are used within classes to define defaultable attributes on actors. They are not valid on classes not derived from Actor.
When registered, a property will be available in the `default` block as `ClassName.PropertyName`. Properties can be given multiple members to initialize.
Property definitions take the form `property Name: Member list...;`.
2018-11-14 13:14:27 -08:00
Properties defined in ZScript are usable from `DECORATE`.
2018-02-08 05:00:46 -08:00
2018-11-14 13:14:27 -08:00
### Default blocks
2018-02-08 05:00:46 -08:00
Default blocks are used on classes derived from Actor to create an overridable list of defaults to properties, allowing for swift creation of flexible actor types.
2018-11-14 13:14:27 -08:00
In `DECORATE`, this is everything that isn't in the `states` block, but in ZScript, for syntax flexibility purposes, it must be enclosed in a block with `default` at the beginning, formed:
2018-02-08 05:00:46 -08:00
```
default
{
Default statement list...
}
```
2018-11-14 13:14:27 -08:00
Default statements include flags and properties. Flags are the same as `DECORATE`, though sub-actor flags require their prefix, and can optionally be followed by a semicolon. Properties are the same as `DECORATE`, with a terminating semicolon required.
2018-02-08 05:00:46 -08:00
2018-11-14 13:14:27 -08:00
### State definitions
2018-02-08 05:00:46 -08:00
2018-11-14 13:14:27 -08:00
These are the same as `DECORATE`, but states that do not have function blocks require terminating semicolons. Double quotes around `####` and `----` are no longer required. State blocks can be subject to Action Scoping with the syntax `states(Scope)`.
2018-02-08 05:00:46 -08:00
2018-02-07 07:03:25 -08:00
Structure definitions
2018-11-14 13:14:27 -08:00
---------------------
2018-02-07 07:03:25 -08:00
2018-08-02 12:13:46 -07:00
A structure is an object type that does not inherit from Object and is not always (though occasionally is) a reference type, unlike classes. Structures marked as `native` are passed by-reference as arguments, and `null` can be passed in their place. Non-native structures cannot be passed as arguments.
2018-02-07 07:03:25 -08:00
Structures are preferred for basic compound data types that do not need to be instanced and are often used as a way of generalizing code. They cannot be returned from functions.
2018-02-08 06:46:25 -08:00
Structures are subject to Scoping.
2018-02-07 07:03:25 -08:00
A structure takes the form of:
```
struct Name [Structure flags...]
{
[Structure content...]
}
```
Optionally followed by a semicolon.
2018-11-14 13:14:27 -08:00
### Structure flags
2018-02-07 07:03:25 -08:00
2018-02-28 13:54:44 -08:00
| Flag | Description |
2018-10-12 16:50:04 -07:00
| ---- | ----------- |
2018-02-28 13:54:44 -08:00
| `clearscope` | Structure has Data scope. Default. |
2018-08-02 12:13:46 -07:00
| `native` | Structure is from the engine. Only usable internally. |
2018-11-14 13:14:27 -08:00
| `play` | Structure has Play scope. |
| `ui` | Structure has UI scope. |
2018-02-28 13:54:44 -08:00
| `version("ver")` | Restricted to ZScript version *ver* or higher. |
2018-02-07 07:03:25 -08:00
2018-11-14 13:14:27 -08:00
### Structure content
2018-02-07 07:03:25 -08:00
Structure contents are an optional list of various things logically contained within the structure, including:
- Member declarations
2018-02-08 05:00:46 -08:00
- Method definitions
2018-02-07 07:03:25 -08:00
- Enumeration definitions
- Constant definitions
2018-02-07 06:25:22 -08:00
Enumeration definitions
2018-11-14 13:14:27 -08:00
-----------------------
2018-02-07 06:25:22 -08:00
An enumeration is a list of named numbers, which by default will be incremental from 0. By default they decay to the type `int`, but the default decay type can be set manually.
An enumeration definition takes the form:
```
enum Name [: IntegerType]
{
2018-02-07 07:03:25 -08:00
[Enumerator...]
2018-02-07 06:25:22 -08:00
}
```
Optionally followed by a semicolon.
Enumerators can either be incremental (from the last enumerator or 0 if there is none) or explicitly set with the basic syntax `enumerator = value`. Enumerators must be followed by a comma unless it is the end of the list.
2018-02-07 08:24:37 -08:00
Constant definitions
2018-11-14 13:14:27 -08:00
--------------------
2018-02-07 08:24:37 -08:00
Constants are simple named values. They are created with the syntax:
```
const Name = value;
```
Constants are not assignable. Their type is inferred from their value, so if you wish for them to have a specific type, you must cast the value to that type.
2018-02-08 05:00:46 -08:00
Static array definitions
2018-11-14 13:14:27 -08:00
-------------------------
2018-02-08 05:00:46 -08:00
2018-02-08 06:54:48 -08:00
Similar to constants, static arrays are named values, but for an array. They are created with the syntax:
```
static const Type name[] = {
[Expression list...]
};
```
Or:
```
static const Type[] name = {
[Expression list...]
};
```
2018-02-08 05:00:46 -08:00
2018-10-10 13:55:53 -07:00
Static arrays cannot be multi-dimensional, unlike normal arrays.
2018-02-07 06:25:22 -08:00
Include directives
2018-11-14 13:14:27 -08:00
------------------
2018-02-07 06:25:22 -08:00
2018-02-28 13:54:44 -08:00
Include directives include other files to be processed by the ZScript compiler, allowing you to organize and separate code into different files. Their syntax is simple:
2018-02-07 06:25:22 -08:00
```
#include "filename"
```
Note that included filenames will conflict with other mods. If two mods have a file named `zscript/MyCoolClasses.zsc` and both include it, expecting to get different files, the engine will fail to load with a script error.
To avoid this, it is suggested to place your ZScript code under a uniquely named sub-folder.
2018-02-07 08:24:37 -08:00
Types
2018-11-14 13:14:27 -08:00
-----
2018-02-07 08:24:37 -08:00
ZScript has several categories of types: Integer types, floating-point (decimal) types, strings, vectors, names, classes, et al. There are a wide variety of ways to use these types, as well as a wide variety of places they are used.
Types determine what kind of value an object stores, how it acts within an expression, etc. All objects, constants and enumerations have a type. Argument lists use types to ensure a function is used properly.
2018-02-28 13:54:44 -08:00
Most basic types have methods attached to them, and both integer and floating-point type names have symbols accessible from them. See the API section for more information.
2018-02-08 09:28:02 -08:00
2018-11-14 13:14:27 -08:00
### Integers
2018-02-07 08:24:37 -08:00
Integer types are basic integral numbers. They include:
2018-08-02 12:13:46 -07:00
| Name | Usable as argument | Bits | Lowest value | Highest value |
| `float` | Yes (64 bits) | 32-bit in structures and classes, 64-bit otherwise. |
| `float64` | Yes | Alias for `double`. |
| `float32` | No | 32-bit floating-point number. Not implemented correctly, unusable. |
2018-02-07 08:24:37 -08:00
2018-11-14 13:14:27 -08:00
### Strings
2018-02-07 08:24:37 -08:00
2018-08-02 12:13:46 -07:00
| Name | Usable as argument |
2018-10-12 16:50:04 -07:00
| ---- | :----------------: |
2018-08-02 12:13:46 -07:00
| `string` | Yes |
2018-08-02 12:23:01 -07:00
The `string` type is a mutable, garbage-collected string reference type. Strings are not structures or classes, however there are methods attached to the type, detailed in the API section.
2018-02-07 08:24:37 -08:00
2018-11-14 13:14:27 -08:00
### Names
2018-02-07 08:24:37 -08:00
2018-08-02 12:13:46 -07:00
| Name | Usable as argument |
2018-10-12 16:50:04 -07:00
| ---- | :----------------: |
2018-08-02 12:13:46 -07:00
| `name` | Yes |
2018-10-12 16:50:04 -07:00
The `name` type is an indexed string. While their contents are the same as a string, their actual value is merely an integer which can be compared far quicker than a string. Names are used for many internal purposes such as damage type names. Strings are implicitly casted to names.
2018-02-07 12:20:54 -08:00
2018-11-14 13:14:27 -08:00
### Color
2018-02-07 12:20:54 -08:00
2018-08-02 12:13:46 -07:00
| Name | Usable as argument |
2018-10-12 16:50:04 -07:00
| ---- | :----------------: |
2018-08-02 12:13:46 -07:00
| `color` | Yes |
2018-10-10 13:55:53 -07:00
The `color` type can be converted from a string using the X11RGB lump or a hex color in the format `#RRGGBB`, or with either `color(R, G, B)` or `color(R, G, B, A)`.
2018-02-07 08:24:37 -08:00
2018-11-14 13:14:27 -08:00
### Vectors
2018-02-07 08:24:37 -08:00
2018-08-02 12:13:46 -07:00
| Name | Usable as argument |
2018-10-12 16:50:04 -07:00
| ---- | :----------------: |
2018-08-02 12:13:46 -07:00
| `vector2` | Yes |
| `vector3` | Yes |
2018-02-07 12:20:54 -08:00
There are two vector types in ZScript, `vector2` and `vector3`, which hold two and three members, respectively. Their members can be accessed through `x`, `y` and (for `vector3`,) `z`. `vector3` can additionally get the X and Y components as a `vector2` with `xy`.
Vectors can use many operators and even have special ones to themselves. See the Expressions and Operators section for more information.
2018-02-07 08:24:37 -08:00
2018-11-14 13:14:27 -08:00
### Fixed-size arrays
2018-02-07 08:24:37 -08:00
2018-08-02 12:13:46 -07:00
| Name | Usable as argument |
2018-10-12 16:50:04 -07:00
| ---- | :----------------: |
2018-08-02 12:13:46 -07:00
| `type[size]` | No |
2018-02-07 12:20:54 -08:00
Fixed-size arrays take the form `Type[size]`. They hold `size` number of `Type` elements, which can be accessed with the array access operator. Multi-dimensional arrays are also supported.
2018-02-07 08:24:37 -08:00
2018-11-14 13:14:27 -08:00
### Dynamic-size arrays
2018-02-07 08:24:37 -08:00
2018-08-02 12:13:46 -07:00
| Name | Usable as argument |
2018-10-12 16:50:04 -07:00
| ---- | :----------------: |
2018-08-02 12:13:46 -07:00
| `array<Type>` | Yes |
2018-11-14 13:14:27 -08:00
Dynamically sized arrays take the form `array<Type>`, and hold an arbitrary number of `Type` elements, which can be accessed with the array access operator.
Dynamic-sized arrays do not have their lifetime scoped to their current block, so:
```
for(int i = 0; i <5;i++)
{
array<int> a;
a.push(0);
}
```
... will result in an array with 5 elements.
Dynamically sized arrays also cannot store other dynamically sized arrays, or `struct` objects.
2018-02-07 08:24:37 -08:00
2018-11-14 13:14:27 -08:00
### Maps
2018-02-07 08:24:37 -08:00
2018-08-02 12:13:46 -07:00
| Name | Usable as argument |
2018-10-12 16:50:04 -07:00
| ---- | :----------------: |
2018-08-02 12:13:46 -07:00
| `map<Type, Type>` | No |
2018-02-07 12:20:54 -08:00
Map types take the form `map<Type, Type>`. They are not yet implemented.
2018-02-07 08:24:37 -08:00
2018-11-14 13:14:27 -08:00
### Class type references
2018-02-07 08:24:37 -08:00
2018-08-02 12:13:46 -07:00
| Name | Usable as argument |
2018-10-12 16:50:04 -07:00
| ---- | :----------------: |
2018-08-02 12:13:46 -07:00
| `class<Type>` | Yes |
| `class` | Yes |
2018-10-12 16:50:04 -07:00
Class type references are used to describe a concrete *type* rather than an object. They simply take the form `class`, and can be restrained to descendants of a type with the syntax `class<Type>`. Strings are implicitly casted to class type references.
2018-02-07 08:24:37 -08:00
2018-11-14 13:14:27 -08:00
### User types
2018-02-07 08:24:37 -08:00
2018-10-12 16:50:04 -07:00
| Name | Usable as argument |
| ---- | :----------------: |
| Any class object | Yes |
| `native` struct object | Yes |
| User struct object | No |
| `@Type` | Yes (only internally) |
2018-08-02 12:13:46 -07:00
2018-02-07 12:20:54 -08:00
Any other identifier used as a type will resolve to a user class, structure or enumeration type.
2018-10-12 16:50:04 -07:00
Identifiers prefixed with `@` are native pointers to objects and not necessarily exposed to ZScript. This is not usable in user code.
2018-02-07 12:20:54 -08:00
A type name that is within a specific scope can be accessed by prefixing it with a `.`. The type `.MyClass.MySubStructure` will resolve to the type `MySubStructure` contained within `MyClass`.
2018-02-07 08:24:37 -08:00
2018-11-14 13:14:27 -08:00
### Read-only types
2018-02-07 08:24:37 -08:00
2018-08-02 12:13:46 -07:00
| Name | Usable as argument |
2018-10-12 16:50:04 -07:00
| ---- | :----------------: |
2018-08-02 12:13:46 -07:00
| `readonly<Type>` | Yes |
2018-11-14 13:14:27 -08:00
A read-only type, as its name implies, may only be read from, and is effectively immutable. They take the form `readonly<Type>`. Do note that this is separate from the member declaration flag.
2018-02-07 08:24:37 -08:00
2018-11-14 13:14:27 -08:00
### Other types
2018-10-12 16:50:04 -07:00
| Name | Usable as argument | Description |
| ---- | :----------------: | ----------- |
| `bool` | Yes | Holds one of two values: `true` or `false`. |
| `sound` | Yes | Holds a sound reference. |
| `spriteid` | Yes | Holds a sprite reference. |
| `state` | Yes | A reference to an actor state. |
| `statelabel` | Yes | The name of an actor state. |
2018-11-14 13:14:27 -08:00
| `textureid` | Yes | Holds a texture reference. |
2018-10-12 16:50:04 -07:00
| `void` | No | Alias for `None`. Unknown purpose, likely implementation error. |
| `voidptr` | No | A pointer to a real memory address. Implementation detail. |
Strings will implicitly convert to `sound` and `statelabel`.
2018-02-07 12:20:54 -08:00
Expressions and Operators
2018-11-14 13:14:27 -08:00
-------------------------
2018-02-07 12:20:54 -08:00
2018-11-14 13:14:27 -08:00
### Literals
2018-02-08 02:54:33 -08:00
Much like C or most other programming languages, ZScript has object literals, including string literals, integer literals, float literals, name literals, boolean literals, and the null pointer.
2018-11-14 13:14:27 -08:00
#### String literals
2018-02-08 02:54:33 -08:00
String literals take the same form as in C:
```
"text here"
```
String literals have character escapes, which are formed with a backslash and a character. Character escapes include:
2018-11-14 13:14:27 -08:00
| Spelling | Output |
| -------- | ------ |
| `\"` | A literal `"`. |
| `\\` | A literal `\`. |
| `\` followed by newline | Concatenates the next line with this one. |
To quote [cppreference](https://en.cppreference.com/w/cpp/language/escape), "of the octal escape sequences, `\0` is the most useful because it represents the terminating null character in null-terminated strings."
2018-02-08 02:54:33 -08:00
2018-02-28 13:54:44 -08:00
String literals, also like C and C++, will be concatenated when put directly next to each other. For example, this:
2018-02-08 02:54:33 -08:00
```
"text 1" "text 2"
```
Will be parsed as a single string literal with the text `"text 1text 2"`.
2018-11-14 13:14:27 -08:00
#### Class type literals
2018-10-12 16:50:04 -07:00
Class type literals take the same form as string literals, but do note that they are not the same.
2018-11-14 13:14:27 -08:00
#### Name literals
2018-02-08 02:54:33 -08:00
Name literals are similar to string literals, though they use apostrophes instead of quote marks:
```
'text here'
```
They do not concatenate like string literals, and do not have character escapes.
2018-11-14 13:14:27 -08:00
#### Integer literals
2018-02-08 02:54:33 -08:00
Integer literals are formed similarly to C. They may take one of three forms, and be typed `uint` or `int` based on whether there is a `u` or `U` at the end or not.
The parser also supports an optional `l`/`L` suffix as in C, though it does not actually do anything, and it is advised you do not use it for potential forward compatibility purposes.
Integer literals can be in the basic base-10/decimal form:
```
1234567890 // int
500u // uint
```
Base-16/hexadecimal form, which may use upper- or lower-case decimals and `0x` prefix, depending on user preference:
```
0x123456789ABCDEF0
0XaBcDeF0 // don't do this, please.
0x7fff
0x7FFFFFFF
```
And, base-8/octal form, prefixed with a `0`:
```
0777
0414444
```
2018-11-14 13:14:27 -08:00
#### Float literals
2018-02-08 02:54:33 -08:00
Float literals, much like integer literals, are formed similarly to C, but they do not support hex-float notation. Float literals support exponent notation.
The parser supports an optional `f`/`F` suffix as in C, though it does not actually do anything, and it is advised you do not use it for potential forward compatibility purposes.
Float literals can be formed in a few ways:
```
0.5 //=> 0.5
.5 //=> 0.5
1. //=> 1.0
```
And with exponents:
```
0.5e+2 //=> 50
50e-2 //=> 0.5
```
2018-11-14 13:14:27 -08:00
#### Boolean literals
2018-02-08 02:54:33 -08:00
The two boolean literals are spelled `false` and `true`, and much like C, can decay to the integer literals `0` and `1`.
2018-11-14 13:14:27 -08:00
#### Null pointer
2018-02-08 02:54:33 -08:00
2018-10-12 16:50:04 -07:00
The null pointer literal is spelled `null` and represents an object that does not exist in memory. Like C, it is not equivalent to the integer literal `0`, and is more similar to C++'s `nullptr`.
2018-02-08 02:54:33 -08:00
2018-11-14 13:14:27 -08:00
### Expressions
2018-02-08 02:54:33 -08:00
2018-11-14 13:14:27 -08:00
Expressions contain literals or othersuch *expressions* of objects, including arithmetic and various conditions.
#### Primary expressions
2018-02-08 02:54:33 -08:00
Basic expressions, also known as primary expressions, can be one of:
- An identifier for a constant or variable.
- The `Super` keyword.
- Any object literal.
- A vector literal.
- An expression in parentheses.
Identifiers work as you expect, they reference a variable or constant. The `Super` keyword references the parent type or any member within it.
2018-11-14 13:14:27 -08:00
##### Vector literals
2018-02-08 02:54:33 -08:00
Vector literals are not under object literals as they are not constants in the same manner as other literals, since they contain expressions within them. As such, they are expressions, not proper value-based literals. They can be formed with:
```
(x, y) //=> vector2, where x is not a vector2
(x, y) //=> vector3, where x *is* a vector2
(x, y, z) //=> vector3
```
2018-10-12 16:50:04 -07:00
All components must have type `double`.
2018-11-14 13:14:27 -08:00
#### Postfix expressions
2018-02-08 02:54:33 -08:00
Postfix expressions are affixed at the end of an expression, and are used for a large variety of things, although the actual amount of postfix expressions is small:
2018-02-28 13:54:44 -08:00
| Form | Description |
2018-10-12 16:50:04 -07:00
| ---- | ----------- |
2018-02-28 13:54:44 -08:00
| `a([Argument list...])` | Function call. |
| `Type(a)` | Type cast. |
| `(class<Type>)(a)` | Class type reference cast. |
| `a[b]` | Array access. |
| `a.b` | Member access. |
| `a++` | Post-increment. This increments (adds 1 to) the object after the expression is evaluated. |
| `a--` | Post-decrement. This decrements (subtracts 1 from) the object after the expression is evaluated. |
2018-02-08 02:54:33 -08:00
2018-11-14 13:14:27 -08:00
#### Unary expressions
2018-02-08 02:54:33 -08:00
Unary expressions are affixed at the beginning of an expression. The simplest example of a unary expression is the negation operator, `-`, as in `-500`. Unary expressions include:
2018-02-28 13:54:44 -08:00
| Form | Description |
2018-10-12 16:50:04 -07:00
| ---- | ----------- |
2018-02-28 13:54:44 -08:00
| `-a` | Negation. |
| `!a` | Logical negation, "not." |
| `++a` | Pre-increment. This adds 1 to the object and evaluates as the resulting value. |
| `--a` | Pre-decrement. This subtracts 1 from the object and evaluates as the resulting value. |
| `~a` | Bitwise negation. Flips all bits in an integer. |
| `+a` | Affirmation. Does not actually do anything. |
| `alignof a` | Evaluates the alignment of the type of an expression. Unknown purpose. |
2018-11-14 13:14:27 -08:00
| `sizeof a` | Evaluates the size of the type of an expression. Unknown purpose. |
2018-02-08 02:54:33 -08:00
2018-11-14 13:14:27 -08:00
#### Binary expressions
2018-02-08 02:54:33 -08:00
Binary expressions operate on two expressions, and are the most common kind of expression. They are used inline like regular math syntax, ie. `1 + 1`. Binary expressions include:
2018-10-12 16:50:04 -07:00
| Form | Description |
| ---- | ----------- |
| `a + b` | Addition. |
| `a - b` | Subtraction. |
| `a * b` | Multiplication. |
| `a / b` | Division quotient. |
| `a % b` | Division remainder, also known as "modulus." Unlike C, this works on floats, too. |
| `a ** b` | Exponent ("power of.") |
| `a << b` | Left bitwise shift. |
| `a >> b` | Right bitwise shift. |
| `a >>> b` | Right unsigned bitwise shift. |
| `a cross b` | Vector cross-product. |
| `a dot b` | Vector dot-product. |
| `a .. b` | Concatenation, creates a string from two values. |
| `a < b` | `true` if `a` is less than `b`. |
| `a > b` | `true` if `a` is greater than `b`. |
| `a <= b` | `true` if `a` is less than or equal to `b`. |
| `a >= b` | `true` if `a` is greater than or equal to `b`. |
| `a == b` | `true` if `a` is equal to `b`. |
| `a != b` | `true` if `a` is not equal to `b`. |
| `a ~== b` | `true` if `a` is approximately equal to `b`. For strings this is a case-insensitive comparison, for floats and vectors this checks if the difference between the two is smaller than ε. |
| `a && b` | `true` if `a` and `b` are both `true`. |
| `a \|\| b` | `true` if `a` or `b` is `true`. |
| `a is "b"` | `true` if `a`'s type is equal to or a descendant of `b`. |
| `a <>= b` | Signed difference between `a` and `b`. |
| `a & b` | Bitwise AND. |
| `a ^ b` | Bitwise XOR. |
| `a \| b` | Bitwise OR. |
| `a::b` | Scope operator. Not implemented yet. |
2018-02-08 02:54:33 -08:00
2018-11-14 13:14:27 -08:00
##### Assignment expressions
2018-02-08 02:54:33 -08:00
Assignment expressions are a subset of binary expressions which *are never constant expressions*. They assign a value to another value, as one might guess.
2018-02-28 13:54:44 -08:00
| Form | Description |
2018-10-12 16:50:04 -07:00
| ---- | ----------- |
2018-02-28 13:54:44 -08:00
| `a = b` | Assigns `b` to `a`. |
| `a += b` | Assigns `a + b` to `a`. |
| `a -= b` | Assigns `a - b` to `a`. |
| `a *= b` | Assigns `a * b` to `a`. |
| `a /= b` | Assigns `a / b` to `a`. |
| `a %= b` | Assigns `a % b` to `a`. |
| `a <<= b` | Assigns `a << b` to `a`. |
| `a >>= b` | Assigns `a >> b` to `a`. |
2018-02-08 02:54:33 -08:00
| `a >>>= b` | Assigns `a >>> b` to `a`. |
2018-02-28 13:54:44 -08:00
| `a \|= b` | Assigns `a \| b` to `a`. |
| `a &= b` | Assigns `a & b` to `a`. |
| `a ^= b` | Assigns `a ^ b` to `a`. |
2018-02-08 02:54:33 -08:00
2018-11-14 13:14:27 -08:00
#### Ternary expression
2018-02-08 02:54:33 -08:00
The ternary expression is formed `a ? b : c`, and will evaluate to `b` if `a` is `true`, or `c` if it is `false`.
2018-02-07 12:20:54 -08:00
Statements
2018-11-14 13:14:27 -08:00
----------
2018-02-07 12:20:54 -08:00
2018-02-08 04:17:07 -08:00
All functions are made up of a list of *statements* enclosed with left and right braces, which in and of itself is a statement called a *compound statement*, or *block*.
2018-11-14 13:14:27 -08:00
### Compound statements
2018-02-08 04:17:07 -08:00
A compound statement is formed as:
```
{
[Statement list...]
}
```
Note that the statement list is optional, so an empty compound statement `{}` is entirely valid.
2018-11-14 13:14:27 -08:00
### Expression statements
2018-02-08 04:17:07 -08:00
An expression statement is the single most common type of statement in just about any programming language. In ZScript, exactly like C and C++, an expression statement is simply formed with any expression followed by a semicolon. Function calls and variable assignments are expressions, for instance, so it is quite clear why they are common.
2018-11-14 13:14:27 -08:00
### Conditional statements
2018-02-08 04:17:07 -08:00
A conditional statement will, conditionally, choose a statement (or none) to execute. They work the same as in C and ACS.
2018-11-14 13:14:27 -08:00
### Switch statements
2018-02-08 04:17:07 -08:00
2018-08-02 12:13:46 -07:00
A switch statement takes an expression of integer or name type and selects a labeled statement to run. They work the same as in C and ACS.
2018-02-08 04:17:07 -08:00
2018-11-14 13:14:27 -08:00
### Loop statements
2018-02-08 04:17:07 -08:00
ZScript has five loop statements, `for`, `while`, `until`, `do while` and `do until`. `for`, `while` and `do while` work the same as in C, C++ and ACS, while `until` and `do until` do the inverse of `while` and `do while`.
The `for` loop takes a limited statement and two optional expressions: The statement for when the loop begins (which is scoped to the loop,) one expression for checking if the loop should break, and one which is executed every time the loop iterates.
The `while` loop simply takes one expression for checking if the loop should break, equivalent to `for(; a;)`.
The `until` loop is equivalent to `while(!a)`.
2018-02-08 04:25:51 -08:00
`do while` and `do until` will only check the expression after the first iteration is complete. The `do while` and `do until` loops are formed as such:
2018-02-08 04:17:07 -08:00
```
do
Statement
2018-10-12 16:50:04 -07:00
while(a) // unlike C, you don't need a semicolon here
2018-02-08 04:17:07 -08:00
do
Statement
until(a)
```
2018-11-14 13:14:27 -08:00
### Control flow statements
2018-02-08 04:17:07 -08:00
As in C, there are three control flow statements that manipulate where the program will execute statements next, which are available contextually. They are `continue`, `break` and `return`.
`continue` is available in loop statements and will continue to the next iteration immediately.
`break` is available in loop statements and switch statements, and will break out of the containing statement early.
`return` is available in functions. If the function does not return any values, it may only be spelled `return;` and will simply exit the function early. If the function does return values, it takes a comma-separated list for each value returned.
2018-11-14 13:14:27 -08:00
### Local variable statements
2018-02-08 04:17:07 -08:00
2018-11-14 13:14:27 -08:00
Local variable statements are formed in one of 3 ways. The `let` keyword can be used to automatically determine the type of the variable from the initializer, while the other two syntaxes use an explicit type, and initialization is optional.
2018-02-08 04:17:07 -08:00
```
2018-11-14 13:14:27 -08:00
Type a;
Type a[Expression]; // alternate syntax for local array
2018-02-08 04:17:07 -08:00
2018-11-14 13:14:27 -08:00
let a = b;
Type a = b;
Type a = {Expression list...}; // for fixed size array types
Type a[Expression] = {Expression list...};
2018-02-08 04:17:07 -08:00
```
2018-11-14 13:14:27 -08:00
### Multi-assignment statements
2018-02-08 04:17:07 -08:00
2018-11-14 13:14:27 -08:00
Expressions or functions that return multiple values can be assigned into multiple variables with the syntax:
2018-02-08 04:17:07 -08:00
```
[Expression list...] = Expression;
```
2018-11-14 13:14:27 -08:00
### Static array statements
2018-02-08 04:17:07 -08:00
2018-02-08 05:00:46 -08:00
Static arrays can be defined normally as a statement.
2018-02-08 04:17:07 -08:00
2018-11-14 13:14:27 -08:00
### Null statements
2018-02-08 04:17:07 -08:00
A null statement does nothing, and is formed `;`. It is similar to an empty compound statement.
2018-02-07 12:20:54 -08:00
2018-02-08 05:00:46 -08:00
Member declarations
2018-11-14 13:14:27 -08:00
-------------------
2018-02-08 05:00:46 -08:00
2018-02-08 06:46:25 -08:00
Member declarations define data within a structure or class that can be accessed directly within methods of the object (or its derived classes,) or indirectly from instances of it with the member access operator.
A member declaration is formed as so:
```
[Member declaration flags...] Type name;
```
Or, if you want multiple members with the same type and flags:
```
[Member declaration flags...] Type name[, name...];
```
2018-02-28 13:54:44 -08:00
Note that the types Font and CVar are unserializable as members and must be marked transient.
2018-11-14 13:14:27 -08:00
### Member declaration flags
2018-02-08 06:46:25 -08:00
2018-10-12 16:50:04 -07:00
| Flag | Description |
| ---- | ----------- |
2018-11-14 13:14:27 -08:00
| `deprecated("ver")` | If accessed, a script warning will occur on load if the archive version is greater than *ver*. |
| `internal` | Member is only writable from `gzdoom.pk3`. |
| `meta` | Member is read-only static class data. Only really useful on actors, since these can be set via properties on them. |
| `native` | Member is from the engine. Only usable internally. |
| `play` | Member has Play scope. |
2018-10-12 16:50:04 -07:00
| `private` | Member is not visible to any class but this one. |
| `protected` | Member is not visible to any class but this one and any descendants of it. |
| `readonly` | Member is not writable. |
2018-11-14 13:14:27 -08:00
| `transient` | Member is not saved into save games. Required for unserializable objects and recommended for UI context objects. |
| `ui` | Member has UI scope. |
2018-10-12 16:50:04 -07:00
| `version("ver")` | Restricted to ZScript version *ver* or higher. |
2018-02-08 06:46:25 -08:00
2018-02-08 05:00:46 -08:00
Method definitions
2018-11-14 13:14:27 -08:00
------------------
2018-02-08 05:00:46 -08:00
2018-02-08 06:46:25 -08:00
Method definitions define functions within a structure or class that can be accessed directly within other methods of the object (or its derived classes,) or indirectly from instances of it with the member access operator.
Methods marked as `virtual` may have their functionality overridden by derived classes, and in those overrides one can use the `Super` keyword to call the parent function.
If `const` is placed after the function signature and before the function body, the method will not be allowed to modify any members in the object instance it's being called on.
The keyword `void` can be used in place of a type (or type list) to have a method which does not have any return value. Similarly, one can place `void` where the argument list might be, although this is redundant as having no argument list at all is allowed.
2018-08-02 12:13:46 -07:00
Arguments of methods may only be of certain types due to technical limitations. See the type table for a list of which are usable and which are not.
2018-11-14 13:14:27 -08:00
### Method definition flags
2018-02-08 06:46:25 -08:00
2018-10-12 16:50:04 -07:00
| Flag | Description |
| ---- | ----------- |
2018-11-14 13:14:27 -08:00
| `action(scope)` | Same as above, but has an action scope. See "Action Scoping" for more information. |
| `action` | Method has implicit `owner` and `state` parameters, mostly useful on weapons. |
| `clearscope` | Method has Data scope. |
| `deprecated("ver")` | If accessed, a script warning will occur on load if the archive version is greater than *ver*. |
| `final` | Virtual method cannot be further overridden from derived classes. |
| `native` | Method is from the engine. Only usable internally. |
| `override` | Method is overriding a base class' virtual method. |
| `play` | Method has Play scope. |
2018-10-12 16:50:04 -07:00
| `private` | Method is not visible to any class but this one. |
| `protected` | Method is not visible to any class but this one and any descendants of it. |
| `static` | Function is not a method, but a global function without a `self` pointer. |
| `ui` | Method has UI scope. |
| `vararg` | Method doesn't type-check arguments after `...`. Only usable internally. |
| `version("ver")` | Restricted to ZScript version *ver* or higher. |
2018-11-14 13:14:27 -08:00
| `virtual` | Method can be overridden in derived classes. |
| `virtualscope` | Method has scope of the type of the object it's being called on. |
2018-02-08 06:46:25 -08:00
Concepts
========
Action Scoping
--------------
On classes derived from Actor, states and methods can be scoped to a certain subset of uses. This is mainly to differentiate actions which take place in inventory items and weapons, and actions which take place in the actual game map. The available scopes are:
2018-02-28 13:54:44 -08:00
| Name | Description |
2018-10-12 16:50:04 -07:00
| ---- | ----------- |
2018-02-08 06:46:25 -08:00
| `actor` | Actions are called from an actual map object. |
2018-11-14 13:14:27 -08:00
| `item` | Actions are called from an inventory item. |
2018-02-28 13:54:44 -08:00
| `overlay` | Actions are called from a weapon overlay. |
| `weapon` | Actions are called from a weapon. |
2018-02-08 06:46:25 -08:00
Object Scoping
--------------
Most objects are subject to object scoping, which restricts the way data can be used in certain contexts. This is to ensure that the playsim does not get changed by the UI, for instance, or that the playsim doesn't read from the UI and break network synchronization. In other words, it is to prevent a multitude of errors that arise when data is modified or read from the wrong places.
There are three scopes in ZScript: Play, UI, and Data (also known as "clearscope.") The Play scope is used for objects that are part of the game simulation and interact with the world in some way or another, while the UI scope is for objects that have no correlation with the world besides perhaps reading information from it. The Data scope is shared between the two, and must be used carefully.
Here is a chart of data access possibilities for each scope:
2018-02-08 09:28:02 -08:00
| | Data scope | Play scope | UI scope |
2018-10-12 16:50:04 -07:00
| - | ---------- | ---------- | ---------- |
2018-02-08 09:28:02 -08:00
| From Data context | Read/write | Read-only | No access |
| From Play context | Read/write | Read/write | No access |
A format string is a string that specifies the format of a conversion from arbitrary data to a contiguous character string. A format string contains normal characters and *conversion specifiers*. See [this page](https://en.cppreference.com/w/c/io/fprintf) for more information. Differences between C's `printf` and ZScript formats include:
2018-02-08 09:28:02 -08:00
2018-10-12 16:50:04 -07:00
- Since there's no `char` type, `int` is used for `%c`.
-`%s` also works for `name`.
- No `%n` specifier.
- An additional conversion specifier `%B` exists which converts a number to binary.
- An additional conversion specifier `%H` exists which works like `%g` but automatically selects the smallest precision.
2018-02-28 13:54:44 -08:00
2018-10-12 16:50:04 -07:00
API
===
2018-02-28 13:54:44 -08:00
2018-10-12 16:50:04 -07:00
The ZScript API is vast and has some holes which are hard to explain. Some parts are implemented in ways that don't make sense to user code, but are fine to the engine. Because of this, the API shall be documented in pseudo-ZScript which gives an idea of how it works for the modder rather than for the engine.
2018-02-28 13:54:44 -08:00
Type symbols
------------
Integer and floating-point types have symbols which can be accessed through `typename.name`. Here is a list of them.
### Integer types
-`Max`
Maximum value of type.
2018-11-14 13:14:27 -08:00
-`Min`
2018-02-28 13:54:44 -08:00
Minimum value of type.
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
### Floating-point types
2018-02-28 13:54:44 -08:00
2018-11-14 13:14:27 -08:00
-`Dig`
Number of decimal digits in type.
2018-10-12 16:50:04 -07:00
2018-02-28 13:54:44 -08:00
-`Epsilon`
ε value of type.
2018-10-12 16:50:04 -07:00
2018-02-28 13:54:44 -08:00
-`Infinity`
∞ value of type.
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
-`Mant_Dig`
2018-02-28 13:54:44 -08:00
2018-11-14 13:14:27 -08:00
Number of mantissa bits in type.
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
-`Max`
2018-02-28 13:54:44 -08:00
2018-11-14 13:14:27 -08:00
Maximum value of type.
2018-10-12 16:50:04 -07:00
2018-02-28 13:54:44 -08:00
-`Max_Exp`
Maximum exponent bits value of type.
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
-`Max_10_Exp`
2018-02-28 13:54:44 -08:00
2018-11-14 13:14:27 -08:00
Maximum exponent of type.
-`Min_Denormal`
Minimum positive subnormal value of type.
-`Min_Exp`
Minimum exponent bits value of type.
-`Min_Normal`
Minimum value of type.
2018-10-12 16:50:04 -07:00
2018-02-28 13:54:44 -08:00
-`Min_10_Exp`
Minimum exponent of type.
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
-`NaN`
2018-02-28 13:54:44 -08:00
2018-11-14 13:14:27 -08:00
Not-a-Number value of type.
2018-02-28 13:54:44 -08:00
2018-10-12 16:50:04 -07:00
Globals
-------
2018-02-28 13:54:44 -08:00
2018-10-12 16:50:04 -07:00
### Global functions
2018-02-28 13:54:44 -08:00
2018-10-12 16:50:04 -07:00
#### Class handling
2018-02-08 09:28:02 -08:00
```
2018-10-12 16:50:04 -07:00
Type GetDefaultByType(TypeName);
2018-11-14 13:14:27 -08:00
Type New(class typename = ThisClass);
2018-02-08 09:28:02 -08:00
```
2018-10-12 16:50:04 -07:00
-`GetDefaultByType`
2018-02-08 09:28:02 -08:00
2018-10-12 16:50:04 -07:00
Gets the default value of any built-in type.
2018-02-08 09:28:02 -08:00
2018-11-14 13:14:27 -08:00
-`New`
Typically spelled lowercase (`new`), creates an object with type `typename`. Defaults to using the class of the calling object.
2018-10-12 16:50:04 -07:00
#### Random number generation
2018-02-08 09:28:02 -08:00
2018-10-12 16:50:04 -07:00
All of these functions may have `[identifier]` between the function name and the argument list to specify a named RNG table to use.
2018-02-08 09:28:02 -08:00
2018-10-12 16:50:04 -07:00
```
double FRandom(double min, double max);
double FRandomPick(double...);
2018-11-14 13:14:27 -08:00
int Random(int min = 0, int max = 255);
int Random2(uint mask = uint.max);
int RandomPick(int...);
void SetRandomSeed(uint num);
2018-10-12 16:50:04 -07:00
```
2018-02-08 09:28:02 -08:00
2018-11-14 13:14:27 -08:00
-`FRandom`
Returns a random float between `min` and `max`.
-`FRandomPick`
Same as `RandomPick`, but with floats.
2018-10-12 16:50:04 -07:00
-`Random`
2018-02-08 09:28:02 -08:00
2018-10-12 16:50:04 -07:00
Returns a random integer between `min` and `max`.
2018-02-08 09:28:02 -08:00
2018-10-12 16:50:04 -07:00
-`Random2`
2018-02-08 09:28:02 -08:00
2018-10-12 16:50:04 -07:00
Returns a random integer value between `-mask` and `mask`. `mask` is used as a bit mask, so it is recommended to use a value of one less than a power of two (ie. 3, 7, 15, 31, 63, 127, 255...)
2018-02-08 09:28:02 -08:00
2018-10-12 16:50:04 -07:00
-`RandomPick`
2018-02-08 09:28:02 -08:00
2018-10-12 16:50:04 -07:00
Returns one of the provided parameters randomly.
2018-02-08 09:28:02 -08:00
2018-10-12 16:50:04 -07:00
-`SetRandomSeed`
2018-02-28 13:54:44 -08:00
2018-10-12 16:50:04 -07:00
Sets the seed of the RNG table to `num`.
#### Math
2018-02-28 13:54:44 -08:00
```
2018-11-14 13:14:27 -08:00
Type Abs(Type n);
2018-10-12 16:50:04 -07:00
double ATan2(double y, double x);
2018-11-14 13:14:27 -08:00
uint BAM(double angle);
Type Clamp(Type n, Type minimum, Type maximum);
Type Max(Type n, Type maximum);
Type Min(Type n, Type minimum);
2018-10-12 16:50:04 -07:00
double VectorAngle(double x, double y);
2018-02-28 13:54:44 -08:00
```
2018-11-14 13:14:27 -08:00
-`Abs`
2018-02-07 12:20:54 -08:00
2018-11-14 13:14:27 -08:00
Returns `|n|` (absolute of `n`.)
2018-02-08 09:28:02 -08:00
2018-11-14 13:14:27 -08:00
-`ATan2`
2018-02-08 09:28:02 -08:00
2018-11-14 13:14:27 -08:00
Computes the arctangent of `y / x` using the arguments' signs to determine the correct quadrant.
-`BAM`
Returns a byte angle of `angle` (`degrees * (0x40000000 / 90.0)`.)
2018-10-12 16:50:04 -07:00
-`Clamp`
Returns `n` if `n` is more than `minimum` and less than `maximum`, or either of those values if it is not.
2018-11-14 13:14:27 -08:00
-`Max`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
Returns `n` if `n` is less than `maximum`, or `maximum`.
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
-`Min`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
Returns `n` if `n` is more than `minimum`, or `minimum`.
2018-10-12 16:50:04 -07:00
-`VectorAngle`
Same as `ATan2`, but with arguments reversed.
#### Game
2018-02-08 09:28:02 -08:00
```
2018-10-12 16:50:04 -07:00
string G_SkillName();
2018-11-14 13:14:27 -08:00
int G_SkillPropertyInt(int p);
2018-10-12 16:50:04 -07:00
double G_SkillPropertyFloat(int p);
2018-11-14 13:14:27 -08:00
2018-10-12 16:50:04 -07:00
vector3, int G_PickDeathmatchStart();
vector3, int G_PickPlayerStart(int pnum, int flags = 0);
2018-02-08 09:28:02 -08:00
```
2018-10-12 16:50:04 -07:00
-`G_SkillName`
2018-02-08 09:28:02 -08:00
2018-10-12 16:50:04 -07:00
The name of the skill in play.
2018-02-08 09:28:02 -08:00
2018-10-12 16:50:04 -07:00
-`G_SkillPropertyInt`
2018-02-08 09:28:02 -08:00
2018-10-12 16:50:04 -07:00
Returns a skill property. `p` may be:
2018-02-08 09:28:02 -08:00
2018-10-12 16:50:04 -07:00
| Name |
| ---- |
2018-11-14 13:14:27 -08:00
| `SKILLP_ACSReturn` |
2018-10-12 16:50:04 -07:00
| `SKILLP_AutoUseHealth` |
2018-11-14 13:14:27 -08:00
| `SKILLP_DisableCheats` |
2018-10-12 16:50:04 -07:00
| `SKILLP_EasyBossBrain` |
| `SKILLP_EasyKey` |
2018-11-14 13:14:27 -08:00
| `SKILLP_FastMonsters` |
2018-10-12 16:50:04 -07:00
| `SKILLP_Infight` |
2018-11-14 13:14:27 -08:00
| `SKILLP_NoPain` |
2018-10-12 16:50:04 -07:00
| `SKILLP_PlayerRespawn` |
2018-11-14 13:14:27 -08:00
| `SKILLP_RespawnLimit` |
| `SKILLP_Respawn` |
| `SKILLP_SlowMonsters` |
| `SKILLP_SpawnFilter` |
2018-02-08 09:28:02 -08:00
2018-10-12 16:50:04 -07:00
-`G_SkillPropertyFloat`
2018-02-08 09:28:02 -08:00
2018-10-12 16:50:04 -07:00
Returns a skill property. `p` may be:
2018-02-08 09:28:02 -08:00
2018-10-12 16:50:04 -07:00
| Name |
| ---- |
2018-11-14 13:14:27 -08:00
| `SKILLP_Aggressiveness` |
2018-10-12 16:50:04 -07:00
| `SKILLP_AmmoFactor` |
| `SKILLP_ArmorFactor` |
| `SKILLP_DamageFactor` |
2018-11-14 13:14:27 -08:00
| `SKILLP_DropAmmoFactor` |
2018-10-12 16:50:04 -07:00
| `SKILLP_FriendlyHealth` |
2018-11-14 13:14:27 -08:00
| `SKILLP_HealthFactor` |
| `SKILLP_MonsterHealth` |
2018-10-12 16:50:04 -07:00
-`G_PickDeathmatchStart`
Returns the position and angle of a random deathmatch start location.
-`G_PickPlayerStart`
2018-02-08 09:28:02 -08:00
2018-10-12 16:50:04 -07:00
Returns the position and angle of a player start for player `pnum`. `flags` may be:
| Name | Description |
| ---- | ----------- |
| `PPS_FORCERANDOM` | Always randomly picks a random player spawn for this player. |
| `PPS_NOBLOCKINGCHECK` | Does not check if an object is blocking the player spawn. |
#### Sound
2018-02-08 09:28:02 -08:00
```
2018-11-14 13:14:27 -08:00
void SetMusicVolume(float vol);
bool S_ChangeMusic(string music_name, int order = 0, bool looping = true, bool force = false);
Sets the volume of the music relative to the user's volume. Range is 0-1, inclusive.
-`S_ChangeMusic`
Changes the music to `music_name`. If `music_name` is `"*"`, the music will be set to the default music for this level. Will loop if `looping` is true. `force` will force the music to play even if a playlist (from the `playlist` console command) is playing.
`order` may mean something different based on the music format:
| Format | Meaning |
| ------ | ------- |
| Tracker music (`.mod`, `.xm`, etc.) | Specifies the order the song will start at. |
| Multi-track `.ogg`, `.flac`, etc. | Specifies the track to begin playing at. |
| Any other format | No meaning, will be ignored. |
-`S_GetLength`
Returns the length of a sound in seconds. **Potentially non-deterministic if all users in a networked game are not using the same sounds.**
-`S_PauseSound`
Pauses music if `notmusic` is false and all game sounds if `notsfx` is false. Used for instance in the time stop powerup.
-`S_ResumeSound`
Resumes playing music and, if `notsfx` is false, all game sounds as well.
2018-10-12 16:50:04 -07:00
-`S_Sound`
2018-02-08 09:28:02 -08:00
2018-11-14 13:14:27 -08:00
Plays a sound (as defined in `SNDINFO`) from the calling object if it has world presence (is an actor or sector etc.)
2018-02-08 09:28:02 -08:00
2018-10-12 16:50:04 -07:00
`channel` may be:
2018-02-08 09:28:02 -08:00
2018-10-12 16:50:04 -07:00
| Name | Description |
| ---- | ----------- |
| `CHAN_AUTO` | Automatically assigns the sound to a free channel (if one exists.) |
| `CHAN_BODY` | For footsteps and generally anything else. |
2018-11-14 13:14:27 -08:00
| `CHAN_ITEM` | For item pickups. |
| `CHAN_VOICE` | For player grunts. |
| `CHAN_WEAPON` | For weapon noises. |
2018-10-12 16:50:04 -07:00
| `CHAN_5` | Extra sound channel. |
| `CHAN_6` | Extra sound channel. |
| `CHAN_7` | Extra sound channel. |
2018-02-08 09:28:02 -08:00
2018-10-12 16:50:04 -07:00
`channel` may also have the following flags OR'd onto it:
2018-02-08 09:28:02 -08:00
2018-10-12 16:50:04 -07:00
| Name | Description |
| ---- | ----------- |
| `CHAN_LISTENERZ` | Sound ignores height entirely, playing at the listener's vertical position. |
2018-11-14 13:14:27 -08:00
| `CHAN_LOOP` | Continues playing the sound on loop until it is stopped manually. |
2018-10-12 16:50:04 -07:00
| `CHAN_MAYBE_LOCAL` | Does not play sound to other players if the silent pickup compat flag is enabled. |
| `CHAN_NOPAUSE` | Does not pause in menus or when `S_PauseSound` is called. |
| `CHAN_NOSTOP` | Does not start a new sound if the channel is already playing something. |
2018-11-14 13:14:27 -08:00
| `CHAN_UI` | Does not record sound in savegames/demos. |
2018-02-08 09:28:02 -08:00
2018-10-12 16:50:04 -07:00
Additionally, `CHAN_PICKUP` is equivalent to `CHAN_ITEM | CHAN_MAYBE_LOCAL`.
`attenuation` determines the dropoff distance of the sound. The higher the value, the quicker it fades. Constants include:
| `ATTN_NONE` | `0` | Does not drop off at all, plays throughout the whole map. |
| `ATTN_NORM` | `1` | Drops off using the `close_dist` and `clipping_dist` defined in `SNDINFO`. Default. |
| `ATTN_STATIC` | `3` | Drops off quickly, at around 512 units. |
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
#### System
2018-10-12 16:50:04 -07:00
```
uint MSTime();
vararg void ThrowAbortException(string format, ...);
2018-02-28 13:54:44 -08:00
```
2018-10-12 16:50:04 -07:00
-`MSTime`
2018-02-28 13:54:44 -08:00
2018-10-12 16:50:04 -07:00
Returns the number of milliseconds since the engine was started. **Not deterministic.**
-`ThrowAbortException`
Kills the VM and ends the game (without exiting) with a formatted error.
### Global variables
These variables are accessible in any context and are not bound by any specific object.
2018-02-28 13:54:44 -08:00
2018-10-12 16:50:04 -07:00
#### Static info
2018-02-28 13:54:44 -08:00
```
2018-10-12 16:50:04 -07:00
readonly array<class<Actor>> AllActorClasses;
2018-11-14 13:14:27 -08:00
readonly array<PlayerClass> PlayerClasses;
readonly array<PlayerSkin> PlayerSkins;
readonly array<Team> Teams;
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
play DehInfo DEH;
readonly GameInfoStruct GameInfo;
2018-10-12 16:50:04 -07:00
readonly FOptionMenuSettings OptionMenuSettings;
2018-11-14 13:14:27 -08:00
readonly textureid SkyFlatNum;
readonly Weapon WP_NOCHANGE;
2018-02-28 13:54:44 -08:00
```
2018-10-12 16:50:04 -07:00
-`AllActorClasses`
2018-02-28 13:54:44 -08:00
2018-10-12 16:50:04 -07:00
As the name implies, an array of every actor class type reference.
2018-02-28 13:54:44 -08:00
2018-10-12 16:50:04 -07:00
-`PlayerClasses`
2018-11-14 13:14:27 -08:00
An array of all player classes as defined in `MAPINFO`/GameInfo and `KEYCONF`.
2018-10-12 16:50:04 -07:00
-`PlayerSkins`
2018-11-14 13:14:27 -08:00
An array of all player skins as defined in `SKININFO` and `S_SKIN`.
-`Teams`
An array of all teams. Maximum index is `Team.Max`.
2018-10-12 16:50:04 -07:00
-`DEH`
TODO
-`GameInfo`
TODO
-`OptionMenuSettings`
TODO
2018-11-14 13:14:27 -08:00
-`SkyFlatNum`
The texture ID for sky flats. `F_SKY1` by default in Doom.
2018-10-12 16:50:04 -07:00
-`WP_NOCHANGE`
A constant denoting that the weapon the player is currently holding shouldn't be switched from.
#### Game state
```
2018-11-14 13:14:27 -08:00
readonly bool AutomapActive;
readonly bool DemoPlayback;
play uint GameAction;
readonly int GameState;
readonly int GameTic;
readonly uint8 GlobalFreeze;
play LevelLocals Level;
2018-10-12 16:50:04 -07:00
int ValidCount;
```
-`AutomapActive`
`true` if the automap is currently open on the client. **Not deterministic.**
2018-11-14 13:14:27 -08:00
-`DemoPlayback`
User is watching a demo.
2018-10-12 16:50:04 -07:00
-`GameAction`
Current global game action. May be one of:
| Name | Description |
| ---- | ----------- |
2018-11-14 13:14:27 -08:00
| `ga_autoloadgame` | Don't use this. |
| `ga_autosave` | Creates an autosave. |
| `ga_completed` | Don't use this. |
| `ga_fullconsole` | Don't use this. |
| `ga_loadgamehideicon` | Don't use this. |
| `ga_loadgameplaydemo` | Don't use this. |
| `ga_loadgame` | Don't use this. |
2018-10-12 16:50:04 -07:00
| `ga_loadlevel` | Don't use this. |
| `ga_newgame2` | Don't use this. |
2018-11-14 13:14:27 -08:00
| `ga_newgame` | Don't use this. |
| `ga_nothing` | Does nothing. |
| `ga_playdemo` | Don't use this. |
2018-10-12 16:50:04 -07:00
| `ga_recordgame` | Don't use this. |
| `ga_savegame` | Don't use this. |
| `ga_screenshot` | Takes a screenshot. |
2018-11-14 13:14:27 -08:00
| `ga_slideshow` | Don't use this. |
2018-10-12 16:50:04 -07:00
| `ga_togglemap` | Toggles the automap. |
2018-11-14 13:14:27 -08:00
| `ga_worlddone` | Don't use this. |
2018-10-12 16:50:04 -07:00
-`GameState`
Current global game state. May be one of:
| Name | Description |
| ---- | ----------- |
| `GS_DEMOSCREEN` | Inside a level but watching a demo in the main menu. |
2018-11-14 13:14:27 -08:00
| `GS_FINALE` | Reading a cluster end text or at the end sequence. |
2018-10-12 16:50:04 -07:00
| `GS_FULLCONSOLE` | Outside of a level, console only. |
| `GS_HIDECONSOLE` | Outside of a level, console hidden (ie. main menu.) |
2018-11-14 13:14:27 -08:00
| `GS_INTERMISSION` | Inbetween levels. |
| `GS_LEVEL` | Inside a level. |
2018-10-12 16:50:04 -07:00
| `GS_STARTUP` | Game not yet initialized. |
2018-11-14 13:14:27 -08:00
| `GS_TITLELEVEL` | Watching a `TITLEMAP` in the main menu. |
2018-10-12 16:50:04 -07:00
-`GameTic`
Number of game tics passed since engine initialization. **Not deterministic.**
-`GlobalFreeze`
TODO: I have no idea what the difference between this and `Level.Frozen` is.
-`Level`
All level info as defined in LevelLocals.
2018-11-14 13:14:27 -08:00
-`ValidCount`
Don't use this.
2018-10-12 16:50:04 -07:00
#### Client
```
KeyBindings AutomapBindings;
2018-11-14 13:14:27 -08:00
KeyBindings Bindings;
2018-10-12 16:50:04 -07:00
readonly Font BigFont;
2018-11-14 13:14:27 -08:00
readonly int CleanHeight;
readonly int CleanHeight_1;
readonly int CleanWidth;
readonly int CleanWidth_1;
readonly int CleanXFac;
readonly int CleanXFac_1;
readonly int CleanYFac;
readonly int CleanYFac_1;
2018-10-12 16:50:04 -07:00
readonly Font ConFont;
readonly Font IntermissionFont;
2018-11-14 13:14:27 -08:00
readonly Font SmallFont;
readonly Font SmallFont2;
ui float BackbuttonAlpha;
ui int BackbuttonTime;
ui int MenuActive;
2018-10-12 16:50:04 -07:00
ui BaseStatusBar StatusBar;
2018-11-14 13:14:27 -08:00
2018-10-12 16:50:04 -07:00
int LocalViewPitch;
```
2018-11-14 13:14:27 -08:00
-`AutomapBindings`
2018-10-12 16:50:04 -07:00
TODO
2018-11-14 13:14:27 -08:00
-`Bindings`
2018-10-12 16:50:04 -07:00
TODO
2018-11-14 13:14:27 -08:00
-`BigFont`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
The `bigfont` for the current game.
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
-`CleanHeight`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
The current screen height divided by `CleanYFac`. **Not deterministic.**
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
-`CleanHeight_1`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
The current screen height divided by `CleanYFac_1`. **Not deterministic.**
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
-`CleanWidth`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
The current screen width divided by `CleanXFac`. **Not deterministic.**
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
-`CleanWidth_1`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
The current screen width divided by `CleanYFac_1`. **Not deterministic.**
2018-10-12 16:50:04 -07:00
-`CleanXFac`
2018-11-14 13:14:27 -08:00
Integral scaling factor for horizontal positions to scale from 320x200 to the current virtual resolution. **Not deterministic.**
-`CleanXFac_1`
Integral scaling factor for horizontal positions to scale from 320x200 to the current virtual resolution, accounting for aspect ratio differences. **Not deterministic.**
2018-10-12 16:50:04 -07:00
-`CleanYFac`
2018-11-14 13:14:27 -08:00
Integral scaling factor for vertical positions to scale from 320x200 to the current virtual resolution. **Not deterministic.**
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
-`CleanYFac_1`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
Integral scaling factor for vertical positions to scale from 320x200 to the current virtual resolution, accounting for aspect ratio differences. **Not deterministic.**
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
-`ConFont`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
The console font.
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
-`IntermissionFont`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
The font used in intermission screens.
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
-`SmallFont`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
The `smallfnt` for the current game.
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
-`SmallFont2`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
The alternate `smallfnt`.
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
-`BackbuttonAlpha`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
Alpha of the back button in menus.
-`BackbuttonTime`
The time until the back button starts fading out in menus.
2018-10-12 16:50:04 -07:00
-`MenuActive`
The current active menu state. One of:
| Name | Description |
| ---- | ----------- |
| `Menu.Off` | No active menu. |
| `Menu.OnNoPause` | Menu is opened, but the game is not paused. |
2018-11-14 13:14:27 -08:00
| `Menu.On` | Menu is open, game is paused. |
2018-10-12 16:50:04 -07:00
| `Menu.WaitKey` | Menu is opened, waiting for a key for a controls menu binding. |
-`StatusBar`
TODO
-`LocalViewPitch`
The pitch angle (in degrees) of `ConsolePlayer`'s view. **Not deterministic.**
#### Players
```
2018-11-14 13:14:27 -08:00
readonly int ConsolePlayer;
readonly bool Multiplayer;
readonly int Net_Arbitrator;
readonly bool PlayerInGame[MAXPLAYERS];
play PlayerInfo Players[MAXPLAYERS];
2018-10-12 16:50:04 -07:00
```
-`ConsolePlayer`
Number of the player running the client. **Not deterministic.**
2018-11-14 13:14:27 -08:00
-`Multiplayer`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
Game is networked.
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
-`Net_Arbitrator`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
Number of the player who initiated or currently hosts the game.
2018-10-12 16:50:04 -07:00
-`PlayerInGame`
`true` if the player is currently in-game.
2018-11-14 13:14:27 -08:00
-`Players`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
PlayerInfo structs for each player.
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
Built-in Types
--------------
2018-10-12 16:50:04 -07:00
### Array
While ZScript does not have proper user-facing generics, `Array` is one such type that does have a type parameter. It mirrors the internal `TArray` type.
```
struct Array<Type>
{
2018-11-14 13:14:27 -08:00
void Clear();
2018-10-12 16:50:04 -07:00
void Copy(array<Type> other);
void Delete(uint index, int count = 1);
2018-11-14 13:14:27 -08:00
uint Find(Type item) const;
2018-10-12 16:50:04 -07:00
void Grow(uint amount);
2018-11-14 13:14:27 -08:00
void Insert(uint index, Type item);
2018-10-12 16:50:04 -07:00
uint Max() const;
2018-11-14 13:14:27 -08:00
void Move(array<Type> other);
bool Pop();
uint Push(Type item);
uint Reserve(uint amount);
void Resize(uint amount);
void ShrinkToFit();
2018-10-12 16:50:04 -07:00
uint Size() const;
}
```
2018-11-14 13:14:27 -08:00
-`Clear`
Clears out the entire array.
2018-10-12 16:50:04 -07:00
-`Copy`
Copies another array's contents into this array.
2018-11-14 13:14:27 -08:00
-`Delete`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
Deletes `count` object(s) at `index`. Moves objects after them into their place.
2018-10-12 16:50:04 -07:00
-`Find`
Finds the index of `item` in the array, or `Size` if it couldn't be found.
2018-11-14 13:14:27 -08:00
-`Grow`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
Ensures the array can hold at least `amount` new members.
2018-10-12 16:50:04 -07:00
-`Insert`
Inserts `item` at `index`. Moves objects after `index` to the right.
2018-11-14 13:14:27 -08:00
-`Max`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
Returns the allocated size of the array.
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
-`Move`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
Moves another array's contents into this array.
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
-`Pop`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
Deletes the last item in the array. Returns `false` if there are no items in the array.
-`Push`
Places `item` at the end of the array, calling `Grow` if necessary.
2018-10-12 16:50:04 -07:00
-`Reserve`
Adds `amount` new entries at the end of the array, increasing `Size`. Calls `Grow` if necessary.
2018-11-14 13:14:27 -08:00
-`Resize`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
Changes the allocated array size to `amount`. Deletes members if `amount` is smaller than `Size`.
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
-`ShrinkToFit`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
Shrinks the allocated array size `Max` to `Size`.
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
-`Size`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
Returns the amount of objects in the array.
2018-10-12 16:50:04 -07:00
### Color
2018-11-14 13:14:27 -08:00
Colors simply store red, green, blue and alpha components. Each component has a range 0 to 255, inclusive.
2018-10-12 16:50:04 -07:00
```
struct Color
{
uint8 r, g, b, a;
}
```
### FixedArray
Fixed-size arrays have a size method attached to them for convenience purposes.
```
struct FixedArray
{
uint Size() const;
}
```
-`Size`
Returns the size of the array. This is a compile-time constant.
### String
```
struct String
{
static vararg string Format(string format, ...);
vararg void AppendFormat(string format, ...);
2018-11-14 13:14:27 -08:00
2018-10-12 16:50:04 -07:00
string CharAt(int pos) const;
2018-11-14 13:14:27 -08:00
int CharCodeAt(int pos) const;
2018-10-12 16:50:04 -07:00
string Filter();
2018-11-14 13:14:27 -08:00
int IndexOf(string substr, int start = 0) const;
string Left(int len) const;
uint Length() const;
string Mid(int pos = 0, int len = int.max) const;
void Remove(int index, int amount);
void Replace(string pattern, string replacement);
int RightIndexOf(string substr, int end = int.max) const;
deprecated("3.5.1") int LastIndexOf(string substr, int end = int.max) const;
2018-10-12 16:50:04 -07:00
}
```
-`Format`
Creates a string using a format string and any amount of arguments.
-`AppendFormat`
Works like `Format`, but appends the result to the string.
-`CharAt`
Returns the character at `pos` as a new string.
-`CharCodeAt`
Returns the character at `pos` as an integer.
-`Filter`
Replaces escape sequences in a string with escaped characters as a new string.
-`IndexOf`
Returns the first index of `substr` starting from the left at `start`.
2018-11-14 13:14:27 -08:00
-`Left`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
Returns the first `len` characters as a new string.
-`Length`
Returns the number of characters in this string.
-`Mid`
Returns `len` characters starting at `pos` as a new string.
-`Remove`
Removes `amount` characters starting at `index` in place.
-`Replace`
Replaces all instances of `pattern` with `replacement` in place.
2018-10-12 16:50:04 -07:00
-`RightIndexOf`
Returns the first index of `substr` starting from the right at `end`.
2018-11-14 13:14:27 -08:00
-`Split`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
Splits the string by each `delimiter` into `tokens`. `keepEmpty` may be either `TOK_SKIPEMPTY` (the default) or `TOK_KEEPEMPTY`, which will keep or discard empty strings found while splitting.
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
-`ToDouble`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
Interprets the string as a double precision floating point number.
2018-10-12 16:50:04 -07:00
-`ToInt`
Interprets the string as a base `base` integer, guessing the base if it is `0`.
2018-11-14 13:14:27 -08:00
-`ToLower`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
Converts all characters in the string to lowercase in place.
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
-`ToUpper`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
Converts all characters in the string to uppercase in place.
-`Truncate`
Truncates the string to `len` characters in place.
-`LastIndexOf`
Broken. Use `RightIndexOf` instead.
2018-10-12 16:50:04 -07:00
### TextureID
Texture IDs can be explicitly converted to integers, but not the other way around. You can add and subtract integers with a `textureid`, however. (This only works with the integer on the right hand side.)
```
struct TextureID
{
bool Exists() const;
2018-11-14 13:14:27 -08:00
bool IsNull() const;
bool IsValid() const;
2018-10-12 16:50:04 -07:00
void SetInvalid();
void SetNull();
}
```
2018-11-14 13:14:27 -08:00
-`Exists`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
Checks if the texture exists within the texture manager at all.
2018-10-12 16:50:04 -07:00
-`IsNull`
Checks if the texture is the null index (`0`.)
2018-11-14 13:14:27 -08:00
-`IsValid`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
Checks if the texture index is not the invalid index (`-1`.)
2018-10-12 16:50:04 -07:00
-`SetInvalid`
Sets the texture index to `-1`.
-`SetNull`
Sets the texture index to `0`.
The proper way to zero-initialize a `textureid` is:
```
textureid tex;
tex.SetNull();
```
### Vector2/Vector3
```
struct Vector2
{
double x, y;
2018-11-14 13:14:27 -08:00
double Length() const;
2018-10-12 16:50:04 -07:00
vector2 Unit() const;
}
struct Vector3
{
double x, y, z;
vector2 xy;
2018-11-14 13:14:27 -08:00
double Length() const;
2018-10-12 16:50:04 -07:00
vector3 Unit() const;
}
```
-`Length`
Returns the length (magnitude) of the vector.
-`Unit`
Returns a normalized vector. Equivalent to `vec / vec.length()`.
2018-11-14 13:14:27 -08:00
Object
------
The base class of all `class` types.
```
class Object
{
bool bDestroyed;
class GetClass();
string GetClassName();
class GetParentClass();
virtualscope void Destroy();
virtual virtualscope void OnDestroy();
}
```
-`bDestroyed`
This object wants to be destroyed but has not yet been garbage collected.
-`GetClass`
Returns the class type of this object.
-`GetClassName`
Returns a string representation of the class type of this object.
-`GetParentClass`
Returns the class type of this object's parent class.
-`Destroy`
Destroys this object. Do not use the object after calling this. References to it will be invalidated.
-`OnDestroy`
Called when the object is collected by the garbage collector. **Not deterministic.**
2018-10-12 16:50:04 -07:00
Level Data
----------
### Vertex
```
struct Vertex play
{
readonly vector2 p;
}
```
-`p`
The point this object represents.
### Side
Also known as a "sidedef." One of the textured sides of a line. Each sidedef has three portions: Upper, middle, and lower. The middle texture is special as it can have transparency.
The three portions of a sidedef can be referred to with:
A player class as defined in either `MAPINFO`/GameInfo or `KEYCONF`.
2018-10-12 16:50:04 -07:00
```
struct PlayerClass
{
uint Flags;
array<int> Skins;
2018-11-14 13:14:27 -08:00
class<Actor> Type;
2018-10-12 16:50:04 -07:00
bool CheckSkin(int skin);
void EnumColorsets(out array<int> data);
name GetColorsetName(int setnum);
}
```
-`Flags`
Not currently implemented correctly, `PCF_NOMENU` does not exist in ZScript, but its value is `1` if you need to check for that.
-`Skins`
Skin indices available to this player class.
2018-11-14 13:14:27 -08:00
-`Type`
The class type reference for this player class.
2018-10-12 16:50:04 -07:00
-`CheckSkin`
Checks if `skin` is in `Skins`.
-`EnumColorsets`
TODO
-`GetColorsetName`
TODO
### PlayerSkin
2018-11-14 13:14:27 -08:00
A player skin as defined in `SKININFO` or `S_SKIN`.
2018-10-12 16:50:04 -07:00
```
struct PlayerSkin
{
2018-11-14 13:14:27 -08:00
int CrouchSprite;
2018-10-12 16:50:04 -07:00
string Face;
uint8 Gender;
2018-11-14 13:14:27 -08:00
int NameSpc;
2018-10-12 16:50:04 -07:00
bool OtherGame;
2018-11-14 13:14:27 -08:00
uint8 Range0End;
uint8 Range0Start;
2018-10-12 16:50:04 -07:00
vector2 Scale;
2018-11-14 13:14:27 -08:00
string SkinName;
2018-10-12 16:50:04 -07:00
int Sprite;
}
```
2018-11-14 13:14:27 -08:00
-`CrouchSprite`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
The crouching sprite ID for this skin.
2018-10-12 16:50:04 -07:00
-`Face`
Prefix for statusbar face graphics.
-`Gender`
2018-11-14 13:14:27 -08:00
Default gender of the skin. May be one of the following:
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
| Name | Value | Description |
| ---- | :---: | ----------- |
| `GENDER_FEMALE` | `1` | Feminine. |
| `GENDER_MALE` | `0` | Masculine. |
| `GENDER_NEUTRAL` | `2` | Neutral. |
| `GENDER_OTHER` | `3` | Other (robot, zombie, etc.) |
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
-`NameSpc`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
If this skin was defined in S_SKIN, this is the lump ID of the marker itself.
2018-10-12 16:50:04 -07:00
-`OtherGame`
The player skin is made for another game and needs to be color remapped differently.
2018-11-14 13:14:27 -08:00
-`Range0End`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
The end index of the translation range to be used for changing the player sprite's color.
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
-`Range0Start`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
The beginning index of the translation range to be used for changing the player sprite's color.
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
-`Scale`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
The scaling factor used for the player sprite.
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
-`SkinName`
Name of the skin.
-`Sprite`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
The sprite ID for this skin.
2018-10-12 16:50:04 -07:00
### Team
2018-11-14 13:14:27 -08:00
A team as defined in `TEAMINFO`.
2018-10-12 16:50:04 -07:00
```
struct Team
{
const Max;
2018-11-14 13:14:27 -08:00
const NoTeam;
2018-10-12 16:50:04 -07:00
string mName;
}
```
-`Max`
The maximum number of teams.
2018-11-14 13:14:27 -08:00
-`NoTeam`
A constant index for a player with no team.
2018-10-12 16:50:04 -07:00
-`mName`
The name of the team.
Weapons
-------
### Weapon
TODO
Drawing
-------
### Font
2018-11-14 13:14:27 -08:00
A font as defined in `FONTDEFS` or a ZDoom or bitmap font file.
2018-10-12 16:50:04 -07:00
```
struct Font
{
static Font FindFont(name fontname);
2018-11-14 13:14:27 -08:00
static int FindFontColor(name color);
2018-10-12 16:50:04 -07:00
static Font GetFont(name fontname);
2018-11-14 13:14:27 -08:00
int GetCharWidth(int code);
2018-10-12 16:50:04 -07:00
string GetCursor();
2018-11-14 13:14:27 -08:00
int GetHeight();
int StringWidth(string code);
2018-10-12 16:50:04 -07:00
BrokenLines BreakLines(string text, int maxlen);
}
```
2018-11-14 13:14:27 -08:00
-`FindFont`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
Gets a font as defined in `FONTDEFS`.
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
-`FindFontColor`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
Returns the color range enumeration for a named color.
2018-10-12 16:50:04 -07:00
-`GetFont`
2018-11-14 13:14:27 -08:00
Gets a font either as defined in `FONTDEFS` or a ZDoom/bitmap font.
2018-10-12 16:50:04 -07:00
-`GetCharWidth`
Returns the width in pixels of a character code.
2018-11-14 13:14:27 -08:00
-`GetCursor`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
Returns the string used as a blinking cursor graphic for this font.
2018-10-12 16:50:04 -07:00
-`GetHeight`
Returns the line height of the font.
2018-11-14 13:14:27 -08:00
-`StringWidth`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
Returns the width in pixels of the string.
2018-10-12 16:50:04 -07:00
-`BreakLines`
Breaks `text` up into a `BrokenLines` structure according to the screen and clip region, as well as appropriately accounting for a maximum width in pixels of `maxlen`.
### BrokenLines
A container representing an array of lines of text that have been broken up to fit the screen and clipping region.
```
class BrokenLines
{
2018-11-14 13:14:27 -08:00
int Count();
2018-10-12 16:50:04 -07:00
string StringAt(int line);
2018-11-14 13:14:27 -08:00
int StringWidth(int line);
2018-10-12 16:50:04 -07:00
}
```
-`Count`
Returns the amount of lines in this container.
-`StringAt`
Returns the text of line `line`.
2018-11-14 13:14:27 -08:00
-`StringWidth`
2018-10-12 16:50:04 -07:00
2018-11-14 13:14:27 -08:00
Returns the width (in pixels) of line `line`.
### Shape2D
Represents an arbitrary polygonal 2D shape.
2018-10-12 16:50:04 -07:00
```
2018-11-14 13:14:27 -08:00
class Shape2D
{
void Clear(int which = C_Verts | C_Coords | C_Indices);
void PushCoord(vector2 c);
void PushTriangle(int a, int b, int c);
void PushVertex(vector2 v);
}
```
-`Clear`
Clears data out of a shape. Uses these as a bit flag: