Struct Template (Structure) — oopsk
Addon: oopsk · Category: Structure · Since: 1.0
Syntax
struct <([\p{IsAlphabetic}_][\p{IsAlphabetic}\p{IsDigit}_]*)>Description
Creates a struct template. The template name is case insensitive and has the same restrictions as function names. Fields are defined in the format '[const[ant]] <fieldname>: <fieldtype> [= %object%]'. Their names are case insensitive and consist of letters, underscores, and spaces. No two fields in the same template can have the same name. The field type can be a single type or a plural type. The default value can be set by adding an optional '= value' at the end of the line.The default value will be evaluated when the struct is created. Fields can be marked as constant by adding 'const' or 'constant' at the beginning of the line. Constant fields cannot be changed after the struct is created. Dynamic fields can be made by adding 'dynamic' to the beginning of the line. Dynamic fields require a default value and will always re-evaluate their value each time they are called. This means they cannot be changed directly, but can rely on the values of other fields or even functions. Converters can be defined in a 'converts to:' section. Each converter is defined in the format '<target type> via %expression%'. Note that oopsk cannot generate chained converters reliably, so you should expressly define converters for all target types you wish to convert to. Be careful when using converters, as they can cause unexpected behavior in all of your scripts if not used properly.Best practice is to ensure you reload all scripts after defining or modifying struct templates to ensure all converters are registered correctly.
Examples
struct message:
sender: player
message: string
const timestamp: date = now
attachments: objects
converts to:
string via this->message
struct Vector2:
x: number
y: number
dynamic length: number = sqrt(this->x^2 + this->y^2)
struct CustomPlayer
const player: player
rank: string = "Member"
dynamic isAdmin: boolean = whether this->rank is "Admin"
converts to:
player via this->player
location via this->player's location