Classes in Verse
In Verse, a class is a template for creating objects with similar behaviors and properties. It is a composite type, which means that it’s bundled data of other types and functions that can operate on that data.
Classes are hierarchical, which means that a class can inherit information from its parent (superclass) and share its information with its children (subclasses). Classes can be a custom type defined by the user. Compare to instance.
For example, let’s say you want to have multiple cats in your game. A cat has a name and an age, and they can meow. Your cat class could look like this:
| | |
| --- | --- |
| | cat := class: |
| | Name : string |
| | var Age : int = 0 |
| | Sound : string |
| | |
| | Meow() : void = DisplayMessage(Sound) |
cat := class: Name : string var Age : int = 0 Sound : string Meow() : void = DisplayMessage(Sound)
Copy full snippet(6 lines long)
Definitions of variables that are nested inside the class define fields of the class. Functions defined inside a class may also be called methods. Fields and methods are referred to as class members. In the above example, Sound is a field, and Meow is a method of cat.
You're reading a preview
The full reference is free for BrainDeadGuild Discord members — sign in to read it all, or open the original at the source.
Sign in with your BrainDead.TV / BrainDeadGuild Discord account for full access.