From 43a69c445fe340c73347c36646391162bac30256 Mon Sep 17 00:00:00 2001 From: Michieal Date: Thu, 1 Dec 2022 23:44:38 +0000 Subject: [PATCH] Added in Error Handling The /ver command now has error handling, so that it will work regardless of minetest version, and will tell the user to update the minetest version for support. Also updated the mod.conf to have the author field filled out. todo: still needs translation files. --- mods/HUD/mcl_ver_info/init.lua | 28 ++++++++++++++++++++++++---- mods/HUD/mcl_ver_info/mod.conf | 1 + 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/mods/HUD/mcl_ver_info/init.lua b/mods/HUD/mcl_ver_info/init.lua index 345f36833..796245e56 100644 --- a/mods/HUD/mcl_ver_info/init.lua +++ b/mods/HUD/mcl_ver_info/init.lua @@ -3,10 +3,26 @@ --- Created by Michieal. --- DateTime: 11/28/22 4:38 PM --- - local modname = minetest.get_current_modname() local S = minetest.get_translator(modname) +local function xpcall_ver (error) + minetest.log("error", error) +end + +local function get_game_info () + local game_info + + if xpcall(minetest.get_game_info, xpcall_ver) then + game_info = minetest.get_game_info() + else + minetest.log( S("Sorry, but your version of Minetest doesn't support the latest API. Please upgrade your minetest.")) + return false + end + + return game_info +end + -- register normal user access to debug levels 1 and 0. minetest.register_chatcommand("ver", { description = S("Display Mineclone 2 game version."), @@ -20,7 +36,11 @@ minetest.register_chatcommand("ver", { path = string, } --]] - local game_info = minetest.get_game_info() + local game_info = get_game_info () + + if game_info == false then + return true + end if game_info.title == nil or game_info.title == "" then game_info.title = "Mineclone 2" @@ -29,8 +49,8 @@ minetest.register_chatcommand("ver", { game_info.id = " Please upgrade your version to the newest version for the /ver command to work." end - minetest.chat_send_player(name, string.format("Version: %s - %s",game_info.title, game_info.id) ) + minetest.chat_send_player(name, string.format("Version: %s - %s", game_info.title, game_info.id)) return true - end + end }) diff --git a/mods/HUD/mcl_ver_info/mod.conf b/mods/HUD/mcl_ver_info/mod.conf index 66c5e5c7e..b6f6dca98 100644 --- a/mods/HUD/mcl_ver_info/mod.conf +++ b/mods/HUD/mcl_ver_info/mod.conf @@ -1,3 +1,4 @@ name = mcl_ver_info description = Prints game version information; /ver command. depends = mcl_init +author = Michieal