πŸ“šCreating Libraries

circle-info

This resource only goes over the basics of library development. If you wish to learn more about libraries, please go here.

Libraries allow users to write pre-written, reusable code that can be imported anywhere, at any time. This is useful if you often reuse portions of your code in multiple scripts, or if you wish to compartmentalize your scripts and have a cleaner code base.

In Fatality, libraries are divided into two categories: Local libraries and Cloud libraries. Local libraries are located in your fatality/scripts/lib folder and may only be used by other local scripts, meanwhile cloud libraries are similar to cloud scripts and can be shared and imported by any other cloud script through the workshop. Despite that difference, libraries follow the same code structure:

-- Usually, a 'module' table is created and all of your libraries contents go into it.
local M = {}

-- You can export functions.
function M.MyFunction()
    print('Call from my library')
end

-- Or constants.
M.MyValue = 979

-- Or any other value.
M.MenuElement = gui.Checkbox('external_checkbox')

-- At the end of every library, make sure to return the contents you wanna export!
return M

You may then import said library from another file using either its file name or identifier.

Last updated