Community Forum

Splitting mod in multiple files

Forum Overview >> Scripting

Created11.06.2021 10:57

Simone Santillo (Sismo) 11.06.2021 10:57
Hi everyone,
I have almost concluded the scripting for my own mod and, since it has grown 1k lines long, I wanted to refactor a bit by moving object classes into their own files and creating a "custom utility library", so that I can reuse code between these files and it will be easier to add feature / fix bugs.
I have tried using the "require" function from LUA standard, but the game gives me the error:
"attempt to call global 'require' (a nil value)"

Am i doing something wrong or are require / loadfile / dofile "banned" from the mod scripting?
Is there any other way to achieve what I mentioned above?

Thanks to everyone for any solution or pointers.

Bilbo Beutlin (BBeutlin) 11.06.2021 13:02
- source(filename)
eg. if the file is in the same mod directory
- source(Utils.getFilename("example.lua", g_currentModDirectory))

This must be in the main code, not inside functions. Best place is just at begin.

Simone Santillo (Sismo) 11.06.2021 15:42
Wow, perfectly on point! Did not know about the existence of this "source" function.
Thank you very much!

Note: Log in to post. Create a new account here.