Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Enums

Enums are collections of identifiers that can be used as types.

Basic Syntax

An enum can be declared using the enum keyword:

enum BreakfastFood:
	pancake;
	hash_brown;
	burger;

By default, an enum identifier will generate as its index.

SillyScript JSON

The SillyScript definition call:

hash_brown;

The equivalent JSON:

[
	1
]

Underlying Type

An enum can generate as other types. Simple add an -> TYPE after the enum name to dictate what type it’s converted to.

Currently only string and int are supported.

SillyScript JSON

The SillyScript definition call:

enum BreakfastFood -> string:
	pancake;
	hash_brown;
	burger;
 
burger;

The equivalent JSON:

[
	"burger"
]

Argument

An enum’s name can be used as an argument.

SillyScript JSON

The SillyScript definition call:

enum BreakfastFood -> string:
	pancake;
	hash_brown;
	burger;
 
def Eat(food: BreakfastFood) -> dict:
	action: "eat";
	food: food;
 
Eat(pancake);
Eat(burger);

The equivalent JSON:

[
	{
		"action": "eat",
		"food": "pancake"
	},
	{
		"action": "eat",
		"food": "burger"
	}
]