From cef9f69717b8dcb9705e55023d6712906aefeaeb Mon Sep 17 00:00:00 2001 From: Li0n Date: Fri, 25 Feb 2022 21:55:03 +0100 Subject: [PATCH] validate settings input strings --- init.lua | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/init.lua b/init.lua index 663b6c7..72f48d0 100644 --- a/init.lua +++ b/init.lua @@ -46,15 +46,31 @@ end) minetest.register_chatcommand("strength", { description = "set max rumble strength (between 0 and 1)", func = function(text) - rumble_strength_max = (text) - minetest.display_chat_message("max rumble strength set to "..rumble_strength_max) + if (string.match((text), "^%d+$")) then + rumble_strength_max = (text) + minetest.display_chat_message("max rumble strength set to "..rumble_strength_max) + else + minetest.display_chat_message(minetest.colorize("#FF0", "error: value after .strength should be a positive number")) + end end, }) minetest.register_chatcommand("duration", { description = "set max rumble duration (in seconds)", func = function(text) - rumble_duration_max = (text) - minetest.display_chat_message("max rumble duration set to "..rumble_duration_max) + if (string.match((text), "^%d+$")) then + rumble_duration_max = (text) + minetest.display_chat_message("max rumble duration set to "..rumble_duration_max) + else + minetest.display_chat_message(minetest.colorize("#FF0", "error: value after .duration should be a positive number")) + end + end, +}) + +minetest.register_chatcommand("settings", { + description = "shows current values of settings", + func = function() + minetest.display_chat_message("max rumble strength: "..rumble_strength_max) + minetest.display_chat_message("max rumble duration: "..rumble_duration_max) end, })