> For the complete documentation index, see [llms.txt](https://luffyyy.gitbook.io/beardlib/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://luffyyy.gitbook.io/beardlib/modules/elementsmodule.md).

# Elements

A module used to inject custom mission elements into the game.

### XML Definition

```markup
<Elements directory>
    <element name file/>
</Elements>
```

#### `<Elements directory>`

| Parameter | Type   | Description                                  |
| --------- | ------ | -------------------------------------------- |
| directory | String | Sets the directory to load the elements from |

#### `<element name file/>`

| Parameter | Type   | Description                                                                                                                          |
| --------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------ |
| name      | String | The name of the element, without the "Element" part. If the file parameter isn't define, the assumed file will be \<name>Element.lua |
| file      | String | Let's you choose a specific name for the file of the element's code.                                                                 |

### Simple Usage

```markup
<Elements directory="elements">
    <element name="Food"/>
</Elements>
```

```lua
core:import("CoreMissionScriptElement")
FoodElement = FoodElement or class(CoreMissionScriptElement.MissionScriptElement)

function FoodElement:on_executed(instigator)
	log("Nom nom nom", tostring(self._values.food))
end
```

### Editor Integration

The editor integrates into this module using a hook, the editor will attempt to load an editor class named \<name>ElementEditor.lua, place it in the same directory you'd place your regular element class.

### Notes

1. This guide doesn't cover how to make your own elements (the classes themselves) in depth, this is just a convenient way of injecting them into BeardLib (and the editor) without having to go through the hassle of making hooks and injecting them into BeardLib or the editor.
2. The naming convention differs from the game, instead of ElementFood we force the name to be FoodElement. The reason is to avoid clashing with future or existing element names. This happened before to BeardLib itself. So to avoid this situation this element will work best with this naming convention. This includes the editor's integration.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://luffyyy.gitbook.io/beardlib/modules/elementsmodule.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
