Modules & Imports
Modules can be:
.tfsfiles- Folders containing
module.tfs
Importing modules
// example
let mathmod = loadmodule("./math_module")!;
print(mathmod.add(1, 2)); // 3
NOTE: loadmodule must allways be called with ! as it requires the self variable.
Loading .tfs files as modules:
let module = loadmodule("./module.tfs")!;
module.do_whatever();
You can also load .luau or .lua files as modules:
let mod = loadmodule("./module.luau")!;
let mod2 = loadmodule("./module.lua")!;
In the loadmodule function, after the path to the module you can include loadargs
let mod = loadmodule("./module", "everything after the module path will be a loadarg!", 1, 2, 3)!;
Creating modules
Example module structure:
test_module /
module.tfs OR module.luau OR module.lua
When loadmodule is ran on the module folder, module.tfs, module.luau or module.lua is ran and returned automatically.
Example module code:
let test_module = {
add: ins (a, b) { // NOTE: It's easier to use 'ins' to directly insert a function into a dict entry.
a + b; // Use 'ins' instead of declaring a function and adding a reference to it into the dict.
},
sub: ins (a, b) {
a - b;
}
};
test_module; // modules must always return something!
You can either save this as a .tfs file and load it appropriately to a .tfs file, or you could make a new folder, create a file called module.tfs and insert the code into the file.
You can download and upload modules in PMS.