Lua Script Migration: Difference between revisions
Example of diff mod |
No edit summary |
||
Line 27: | Line 27: | ||
This makes it easy to maintain scripts, as the base game scripts can change. In the old system, if <code>MAP_STATUS_SCRIPT.SetShopkeeperHostile</code> in the base game changed after you copied over event_misc.lua, you would have had to copy the changed version of that method to your own mod to stay updated. Now in the new system, if you don't redefine the method in your mod, you won't have to worry about it. | This makes it easy to maintain scripts, as the base game scripts can change. In the old system, if <code>MAP_STATUS_SCRIPT.SetShopkeeperHostile</code> in the base game changed after you copied over event_misc.lua, you would have had to copy the changed version of that method to your own mod to stay updated. Now in the new system, if you don't redefine the method in your mod, you won't have to worry about it. | ||
This works on common.lua, | This works on common.lua, main.lua, include.lua, and event.lua scripts on the top level (as well as the scripts they call, such as common_vars.lua or event_battle.lua), ground map scripts, and zone scripts. | ||
Services behave slightly differently: they used to . Now they . | Services behave slightly differently: they used to . Now they . | ||
Line 40: | Line 40: | ||
Now you have to load it yourself. | Now you have to load it yourself. | ||
There are 3 fundamental scripts that you have to call if you are modding anything downstream of them: | |||
* main.lua: Services | |||
* common.lua: common_*.lua | |||
* event.lua: event_*.lua | |||
Revision as of 06:10, 30 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, the script event_misc.lua contains the following methods:
function STATUS_SCRIPT.Test(owner, ownerChar, context, args) function MAP_STATUS_SCRIPT.Test(owner, ownerChar, character, status, msg, args) function MAP_STATUS_SCRIPT.ShopGreeting(owner, ownerChar, character, status, msg, args) function MAP_STATUS_SCRIPT.SetShopkeeperHostile(owner, ownerChar, character, status, msg, args) function ITEM_SCRIPT.Test(owner, ownerChar, context, args) function ITEM_SCRIPT.CastawayCaveShift(owner, ownerChar, context, args) function ITEM_SCRIPT.SleepingCalderaShift(owner, ownerChar, context, args) function REFRESH_SCRIPT.Test(owner, ownerChar, character, args) function SKILL_CHANGE_SCRIPT.Test(owner, character, skillIndices, args)
In the old system, if you wanted to mod just the MAP_STATUS_SCRIPT.ShopGreeting
event, you would need to copy the entire event_misc.lua from the base game, modify MAP_STATUS_SCRIPT.ShopGreeting
, and save it to your mod.
In the new system, all you need to do is create an event.lua with your custom MAP_STATUS_SCRIPT.ShopGreeting
in it, and nothing else.
This makes it easy to maintain scripts, as the base game scripts can change. In the old system, if MAP_STATUS_SCRIPT.SetShopkeeperHostile
in the base game changed after you copied over event_misc.lua, you would have had to copy the changed version of that method to your own mod to stay updated. Now in the new system, if you don't redefine the method in your mod, you won't have to worry about it.
This works on common.lua, main.lua, include.lua, and event.lua scripts on the top level (as well as the scripts they call, such as common_vars.lua or event_battle.lua), 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.
There are 3 fundamental scripts that you have to call if you are modding anything downstream of them:
- main.lua: Services
- common.lua: common_*.lua
- event.lua: event_*.lua
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