...

/

Hello, Bracket Terminal!

Hello, Bracket Terminal!

Learn how to use bracket-lib to extend our program to store its state.

Storing state

The game loop runs by calling our application’s tick() function with every frame. The tick() function doesn’t know anything about our game, so we need a way to store the game’s current status. This is known as the Game state. Everything we need to preserve between frames is kept in our game’s state. At any given moment, the state represents a snapshot of the current game.

Create a new, empty struct named State:

Press + to interact
struct State {}

Displaying “Hello, World” doesn’t require any data storage, so there’s no need to put variables inside our game state.

Implementing traits

Traits are are a way to define shared functionality for objects. Traits are similar to interfaces found in other languages, which we use to define a contract. If a trait is implemented, its functionality is available, and the structure meets the requirements of the trait. We’ll learn more about traits in Creating Traits. Don’t worry about the finer details, yet.

Bracket-lib defines a trait for games’ state structures named ...