# Creating a workaround

{% hint style="info" %}
This tutorial assumes you are familiar with coding in Garry's Mod and creating addons.
{% endhint %}

***

## What is a workaround?

A workaround is a system which can be toggled on & off (in the `Base`'s page menu). Its purpose is mainly to allow users to choose to fix issues & conflicts with external addons. A workaround can be targeted for a specific realm (server, client or both) in order to fix all eventual issues.

All workarounds (except during hot reload) are initialized during the `GM:InitPostEntity` hook, assuming that during this time, all fixable hooks should be defined.

#### Examples

See these two examples from the base:

* [`cptbase_shouldcollide.lua`](https://github.com/Guthen/guthscpbase/blob/master/lua/guthscp/modules/base/workarounds/cptbase_shouldcollide.lua)
* [`playable_piano_playeruse.lua`](https://github.com/Guthen/guthscpbase/blob/master/lua/guthscp/modules/base/workarounds/playable_piano_playeruse.lua)

***

## Setting up the file structure

There are multiple ways of setting up the file structure to define the workarounds:

* creating the Lua file in `lua/autorun/`
* creating the Lua file in `lua/guthscp/base/workarounds/`
* **creating the Lua file in a folder of your module and add it to your** `requires` *(recommended)*

{% hint style="warning" %}
The workaround must be defined as shared (both for server & client)
{% endhint %}

***

## Defining the workaround

Open your script and start by creating a `WORKAROUND` local table which you register as follow:

```lua
local WORKAROUND = {}

guthscp.workaround.register( "my_workaround_id", WORKAROUND )
```

The `WORKAROUND` table is what defines your workaround, it will contains properties like the name, the targeted realm & methods that you will define. You also have to **specify the identifier of your workaround** yourself in the registering function call: **choose a unique & recognizable name** so it doesn't conflict with any other workarounds.

Now, you should fill the required properties:

```lua
local WORKAROUND = {
    name = "My Server-Side Workaround",
    realm = guthscp.REALMS.SERVER,
}
```

This is the bare minimum to make a workaround register in the system and to see it in the `guthscpbase` menu. Of course, edit them as you'll like.

{% hint style="info" %}
For more information about the **workaround** class, read this [page](https://guthen.gitbook.io/guthscp/classes/workaround).
{% endhint %}

***

## Adding logic

{% hint style="warning" %}
TODO
{% endhint %}
