Your First Chapter

Most frameworks nowadays exist only to load modules. And while this is good, there could be so much more. Quill provides base lifecycles for use in Chapters and Characters, and even lets you create your own lifecycle hooks.

YOU WILL LEARN HOW TO

  • Write your own Chapter

  • Use your Chapter's lifecycles

  • Set your Chapter's priority


What is a Chapter?

A Chapter is essentially a singleton which provides functions; another name for this is a "provider". Think of a Roblox service such as TweenService; it provides a dictionary of functions for you to use. Chapters do exactly the same thing, except they are also capable of running independently without anything depending on them.


Writing a Chapter

Now that you have created your book from the Quick Start page, you can begin writing your workflow. Here's what a Chapter might look like:

ServerScriptService.server_book.chapters.example.luau
local Players = game:GetService("Players")

local function player_added(player: Player)
    print(player.Name .. " has joined the game!")
end

local function state_something(statement: string)
    print(statement)
end

-- "init" is a lifecycle hook that always runs first!
local function init()
    Players.PlayerAdded:Connect(player_added)
end

return {
    priority = 1, -- This Chapter isn't important, so a low priority is OK.
    init = init,
    player_added = player_added,
    state_something = state_something,
}

If you did everything correctly, this should now run player_added every time a player joins the game. Well done!


Using a Chapter

Now that you've written your first Chapter, you can use it as if it was a regular module script alongside it running automatically via lifecycle hooks:

local example_chapter = require(path.to.chapter)
example_chapter.state_something("This is a statement!")

This example simply calls the state_something function with a string as its parameter. Easy, right?


Summary

  • Chapters are singletons/providers that act as a library for functions.

  • Lifecycle hooks are automatically called on runtime, allowing you to run Chapters independently.

Last updated