如果你遇到了一下类似的bug:
Error while running event StarsWithSakura::on_string_translated (ID 163)
StarsWithSakura/scripts/core.lua:1709: attempt to index field '?' (a nil value)
stack traceback:
请禁用使用其他on_string_translated函数的mod(该函数主要用于本地化翻译遍历库),或者联系其作者尝试修复或者禁用其init中翻译模块。
bug原因,mod优先级问题,本mod加载优先级较低,因此on_init加载优先级也比较低,在本mod没用使用player.request_translation({"core.language"})函数并产生回调之前使用player.request_translation会导致出现该问题。
解决方法:
1. 请不要在init之中使用player.request_translation函数
2. 采用本模组自带的翻译库: remote.call("sws func", "local_translate", player_index, key, result)
---eg. item-name.iron-plate=Iron Plate
---@param player_index integer player_index
---@param key string item-name
---@param result string iron-plate
---@return string Iron Plate
If you encounter a bug similar to the following:
Error while running event StarsWithSakura::on_string_translated (ID 163)
StarsWithSakura/scripts/core.lua:1709: attempt to index field '?' (a nil value)
stack traceback:
Please disable other mods that use the on_string_translated function (which is mainly used for localization translation iteration), or contact their authors to try and fix it or disable the translation module on init.
Bug cause: Mod priority issue. This mod has a lower loading priority, so the on_init loading priority is also relatively low. Using player.request_translation({"core.language"}) before this mod uses the on_string_translated function and generates a callback can lead to this problem.
Solution:
1. Do not use the player.request_translation function in init.
Use this mod's built-in translation library:
remote.call("sws func", "local_translate", player_index, key, result)
---Example: item-name.iron-plate=Iron Plate
---@param player_index integer player_index
---@param key string item-name
---@param key string iron-plate
---@return string Iron Plate