Warning
Modding capabilities are very embryonic. Expect a lot of improvement and changes in the future.
This documentation is a draft with a few guidelines, it will evolve gradually with the development of modding features.
Documents\Polymorph Games\Foundation\mods
.mod.lua
First, you have to register your new mod:
local myMod = foundation.createMod({ Name = "My First Mod", Author = "Leo", Description = "Best Mod Ever" });
mod.lua
is the only script file from your mod that will be automatically loaded.
In order to include another LUA file, you can call the dofile
function on your mod:
myMod:dofile("anotherscript.lua")
This will execute the script anotherscript.lua
from your mod folder. This will also pass the mod variable myMod
to the script. So you will be able to access myMod
from anotherscript.lua
this way:
local myMod = ... -- retrieve arguments passed to the script -- do stuff with myMod -- ...
In addition, you can pass any number of variable to the called script:
myMod:dofile("anotherscript.lua", 42, "A Super String", { 1, 4, 12 })
local myMod, anInteger, aString, anArray = ... -- retrieve arguments passed to the script
You can enable / disable mods from the Mods
menu.
Be aware that even when a mod is disabled, most of the mod assets are loaded anyway, but are not active.
If you want to fully ignore a mod, you can either remove it from your mods folder, or rename the mod.lua
file into something else (mod_.lua
for instance).
You can log your own logs into foundation log file:
myMod:log("Hello World!") myMod:logWarning("This is a warning!") myMod:logError("This is an error!")
You can also open a blocking message box for debugging purpose:
myMod:msgBox("Hello there!")
Internally, Foundation uses random unique IDs (GUID) to identify most objects and resources. When a new asset is added to the mod, Foundation will create a new ID for it, and will store the association between the “modding name” and the ID of the asset.
The generated_ids.lua
file is where the association is stored. When you distribute your mod, it's important to distribute this file too. It will ensure that all your assets have the same ID from one player's computer to another, hence allowing them to share a save-game for instance.
Modders are encouraged to use mod.io to share their mods. Mods shared this way can be found and downloaded from the in-game mod browser.
Here is the Foundation page: https://foundation.mod.io
You'll have to upload a zip of your mod. Make sure the zip contains directly the mod files (mod.lua
needs to be at the root of the zip).