Lua Script Migration

From PMDOWiki
Revision as of 18:32, 9 June 2024 by IDK (talk | contribs) (categories)

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 .



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.


Automatic Conversion

Lua scripts are saved in a subfolder based on the mod's namespace.

References to require "common" become require "origin.common"

MapStrings is deprecated. This means the initial variable declaration is removed


the initialization method is removed

And Instead, use STRINGS.MapStrings