Introduction
Grost is the programming language of Gobu Engine. You use it to write the behaviour of everything that moves in your game: the player, the enemies, the coins, the menus.
This book teaches Grost from scratch. If you have used GDScript, Python or Lua, it will feel familiar. If it’s your first language, read the chapters in order: each one only uses what you have already seen.
Your first script
Section titled “Your first script”A script is a piece of code that gives something in your game its behaviour. This one says hello when it starts, and then counts the seconds that go by:
module Hello
mut seconds : float = 0.0
fn _ready() void { print("Hello from Grost!")}
fn _process(delta: float) void { seconds += delta}Line by line:
module Hellonames the script. That name is also a tag: a label other scripts can use to find the actor. An actor is each thing in a scene: the player, a coin, a camera.mut seconds : float = 0.0declares a variable: a value with a name.mutmeans it can change,floatis its type (a number with decimals) and0.0is the value it starts with.fn _ready() void { ... }is a function: a block of code with a name. The engine calls this one once, when the actor enters the scene.voidsays it gives nothing back._process(delta)is called on every frame. A frame is one picture of the game, and there are many per second.deltais the seconds since the previous frame.- Blocks go between
{ }. A;at the end of a line is optional.
print writes its text in the editor’s Output panel. When you press Play, you see:
Hello from Grost!Where code lives
Section titled “Where code lives”In Gobu every document (a file you open and edit in the editor) has its own code:
| Document | What for |
|---|---|
.scene | A level: what appears in it, the score, the game flow |
.prefab | Something with its own behaviour: player, enemy, bullet, coin |
.uip | A user interface: menu, HUD, pause screen |
The code is embedded in the document and runs on its root actor, the one at the top of the
document. You can also write standalone .gro files, like the examples in this book.
A glimpse of what’s ahead
Section titled “A glimpse of what’s ahead”This script shows several ideas the book explains chapter by chapter. You don’t need to understand all of it now: it’s here so you can see what Grost does for a game.
Data that tells you when it changes (chapter 8). Here, the health of a character, and whether it is still alive:
MAX_HP :: 100live hp : int = MAX_HPlive alive : bool => hp > 0Reactions to those changes, without checking every frame. upon runs once, the first time its
condition is true; watch runs each time hp changes:
upon not alive { print("game over")}
watch hp(value: int) { print($"hp: {value}/{MAX_HP}")}A coroutine (a function that can pause and carry on later) that waits, can be canceled, and always cleans up on the way out (chapter 10). This one is a poison that takes 10 health every second:
async fn poison(ticks: int) void { defer { print("poison wore off") } for _i : int in range(ticks) { await sleep(1.0) set hp = hp - 10 }}
fn _ready() void { spawn poison(3)}How to read this book
Section titled “How to read this book”- Chapters 1 to 5 cover the core language: values, containers, functions, control flow and structs.
- 6 to 9, how code connects to the game:
use, signals, reactive state and interfaces. - 10 to 14, tools for games: concurrency, ECS, saving the game, input and annotations.
- 15 is for readers coming from GDScript.
Every complete example in this book is compiled by the engine’s tests: when the language changes, the book has to change with it.