# 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.

{% hint style="info" %}
**YOU WILL LEARN HOW TO**

* Write your own Chapter
* Use your Chapter's lifecycles
* Set your Chapter's priority
{% endhint %}

***

## 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](../quick-start) page, you can begin writing your workflow. Here's what a Chapter might look like:

{% tabs %}
{% tab title="Method 1" %}
{% code title="ServerScriptService.server_book.chapters.example.luau" overflow="wrap" lineNumbers="true" %}
```lua
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,
}
```
{% endcode %}
{% endtab %}

{% tab title="Method 2" %}
{% code title="ServerScriptService.server_book.chapters.example.luau" overflow="wrap" lineNumbers="true" %}
```lua
local Players = game:GetService("Players")

local example = {
    priority = 1, -- This Chapter isn't important, so a low priority is OK.
}

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

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

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

return example
```
{% endcode %}
{% endtab %}
{% endtabs %}

If you did everything correctly, this should now run <kbd>player\_added</kbd> 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:

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

This example simply calls the <kbd>state\_something</kbd> 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.
