Lua Script Migration: Difference between revisions
automatic conversion vs manual conversion |
mNo edit summary |
||
Line 56: | Line 56: | ||
These are optional changes that you don't have to make, but is good to clean up files or code no longer needed: | These are optional changes that you don't have to make, but is good to clean up files or code no longer needed: | ||
* | * ★ Deleted bin and lib subfolders | ||
* | * ★ Functions identical to the base game are removed in the mod, for the files of common.lua and event.lua | ||
* Functions identical to the base game are removed in the mod, for the files in ground and zone | * Functions identical to the base game are removed in the mod, for the files in ground and zone |
Revision as of 18:44, 9 June 2024
Between 0.8.1 and 0.8.2, the lua scripting system has changed. When you reserialize mods between these versions, the lua scripts will go through an automatic conversion.
Diff Modding
In the new system, lua scripts are diff modded. This means that instead of having to replace the entire file in the base game, you can chose to just add or redefine functions that you want.
For example...
[example]
Previously, if the base game updated any method in common.lua, you would have to repeat that change in your mod. Now, as long that that method isn't changed in your mod, you don't have to make the manual change yourself.
You can still copy common.lua wholesale in your mod if you want. It's just not recommended for the aforementioned maintainability reason.
This works on common, init, include, and event scripts on the top level (as well as the scripts they call), ground map scripts, and zone scripts.
Services behave slightly differently: they used to . Now they .
Breaking Changes
However, this means that your mod must include the common scripts yourself.
Before you could just override common_vars, and the base game's common.lua would call it.
Now you have to load it yourself.
init.lua must require common, event, and include
Additionally, all lua scripts are namespaced. This way, you can reference methods from the base game specifically. The caveat is that all scripts need to be moved.
When you reserialize mods between these versions, the lua scripts will go through an automatic conversion. Some things will be covered, some will not.
Also, services behave differently now.
Migration Checklist
Items marked with ★ are automatically converted on reserialization from versions <=0.8.1 to >=0.8.2
- ★ Lua scripts are moved to a subfolder based on the mod's namespace.
- ★ References to
require "common"
becomerequire "origin.common"
- ★ MapStrings is deprecated.
- ★ This means the initial variable declaration is removed
- ★ the initialization method is removed
- ★ Instead of
MapStrings
, use STRINGS.MapStrings
- ★ All scripts must be loaded from init.lua
- References to your own scripts
require "yourscript"
changed to include your namespacerequire "yournamespace.yourscript"
- Services behave differently now (how?)
These are optional changes that you don't have to make, but is good to clean up files or code no longer needed:
- ★ Deleted bin and lib subfolders
- ★ Functions identical to the base game are removed in the mod, for the files of common.lua and event.lua
- Functions identical to the base game are removed in the mod, for the files in ground and zone