Some fixes

This commit is contained in:
fed 2023-06-27 23:58:41 +02:00
parent aa8e030ed2
commit f9d8f4c053
2 changed files with 8 additions and 1 deletions

View File

@ -171,7 +171,7 @@ namespace mod_stats
return get_stats().access<nlohmann::json>([&](mod_stats_t& stats)
-> nlohmann::json
{
if (!stats.is_object() || !stats[name].is_object() || stats[name].is_null())
if (!stats.is_object() || !stats[name].is_object() || stats[name][field].is_null())
{
return default_value;
}

View File

@ -534,6 +534,13 @@ namespace ui_scripting
return json_to_lua(mod_stats::get_struct(mapname, key));
};
mods_stats_table["getstructor"] = [](const std::string& mapname,
const std::string& key, const script_value& default_value)
{
const auto json_default_value = lua_to_json(default_value);
return json_to_lua(mod_stats::get_struct(mapname, key, json_default_value));
};
mods_stats_table["save"] = mod_stats::write;
mods_stats_table["getall"] = []()
{