WorldMiner

by Xp1000

Welcome to the adventurous world of World Miner! Embark on an exciting journey where you'll explore world chunk by chunk, to uncover precious resources, valuable rocks yielding rare ores and lurking dangers.

Scenarios
1 year, 4 months ago
1.1
550
Environment

b Re-loading a game leaves local tables uninitialized

1 year, 4 months ago

Because the ore tables and stuff are local and not stored in global, they don't persist after saving and loading. (the source of the code was a server, which never saved/loaded and unfortunately wrote their code without caring about init, config change, and loading)

core/config/config.lua will be the source of many bugs or just bad behaviors, because the config table only gets changed on init.

To fix it for new players, you can assign it to global.config or w/e and then use that wherever you need it, instead of using the config from a require at the top. Keep the require in map_helper for init/config_change, then remove ALL of the other requires, it is not the right thing to do unless you edit the config on load and never use it outside events. Also, you can do local config = global.config inside functions instead of replacing each specific use of config in a function.

For existing players, it will need to be initialized if it doesn't exist on_configuration_changed.

on_load can be ignored because if you increment the mod version, on_config will raise

at the start of config.on_init, global.config = config . config can get an on_configuration_changed which runs if not global.config then config.init() end Must be added in

At least these files effected:
market.lua
rocks_yield_enemies.lua
rocks_yield_loot.lua
rocks_yield_ore.lua
trees_yield_ore.lua
cell_helper.lua
filler_helper.lua
loot_helper.lua
map_helper.lua
map_functions.lua
utils.lua
all the variant N*Ns
dungeon.lua

A small mention, having config in global will remove the functions on the first save after and put a warning "21674.762 Info LuaValueSaver.cpp:169: WorldMiner: removed 3 lua functions when saving" . It won't cause an error in modhelper.lua because modhelper having require uses the original table for on_init and on_configuration_changed, but on_chunk_generated would need to use the global.config.

It's not a lot of rewriting or time, it's just annoying. I could do an issue report on github and link files/changes there if you want, to compare how I have mine.

1 year, 4 months ago
(updated 1 year, 4 months ago)

'...removed 2 functions when saving'. I had an empty on_load() I was thinking of using.

Another observation was editing the config with on_load is smaller, but the C variable needs game.random, which causes an error (using game.random on_load is a desync). If the random call was done separately, then the config could be changed and still be a local variable, it would just need that table of random-values taken from global and assigned to the config on_init and on_load

1 year, 4 months ago

Indeed, it appears that this is the underlying concern. I will try to fix it soon. However, if you could submit an issue report on GitHub and link files/changes , I would greatly appreciate it. As I am relatively new to modding, there might be certain areas that are a bit messy, like I don't know whether this migration file 31_07_2023_world_miner_0.1.2 is totally necessary. Maybe if I moved some things as you said to the global table and use on_configuration_changed properly it would be not necessary. I will take a look into this.

Thank you.

1 year, 4 months ago

Fixed in 0.1.4

This thread has been locked.