Code:Type Reference

From Warlords Wiki
Jump to: navigation, search

A type is a class that any value can fall into. There are many types in wlcode, each with a distinct purpose. This is a reference for all of them.

Unit

A Unit is the most basic type in wlcode. It has exactly one value: Unit (hence the name). It is typically used to signify the lack of a return value, as a placeholder, or as a soft indication of an error where throwing an error does not suffice (the conversion builtins have this usage).

Bool

A Bool, or Boolean, has exactly two values: true and false. It is usually returned from a condition expression, for example the builtin <=. They can be tested with an if statement.

Number

A number is a IEEE-754 double-precision floating-point number. If you don't know what that means, that's fine ­— Basically, it can represent any real number. There is many builtins for operating on these, which implement the typical arithmetic we're used to.

String

A string is a sequence of characters, i.e. text.

Enums

An enum is a string with a specific value. These are based off of enums in the Spigot API, however they are named slightly differently: they're lowercased and have dashes instead of underscores. For example, the block type BLACK_STAINED_GLASS becomes black-stained-glass. Below is a list of enums, and links to the spigot API pages which hold the list of them

EntityType

Represents the type of an entity. API link

GameMode

One of the 4 possible game modes. API link

PotionEffect

Represents a potion effect. API link

Sound

Represents a sound. API link

Material

The type of an item or block. API link

List

A list is a list of multiple values, all in one. The first item in the list is labelled with index 0, the second with 1, and so on. These indices can be used in list-get, list-set and other list functions. Sometimes, a list may be written with angular brackets (<>) and another type inside them (e.g. List<Int>). This means that it's a list of that type.

Map

A map is a key-value mapping, where the keys are strings and the values are anything else. This means that the indices can be any string, unlike lists where they're integers. This is useful, for example, for saving scores for specific players; where you could have a map from player UUIDs to scores. Maps can be manipulated via map-get and map-set. Similar to lists, there may be a type specified in angular brackets; this has the same purpose.

Entity

An entity represents an entity in the world.

Player

A player is not a distinct type, but is used in signatures to denote that the entity must be a player.

Item

Represents any item. When compared via =, it only checks the material, name, and lore, but does not check the item amount.

Location

Represents a location in the world. As a block in code, pitch and yaw are optional, and will be set to 0 if not specified.

Any

Used in signatures to denote that the value may be of any type.