From 42aed43d2dc19f6161837fe9ccfba1cdc44442be Mon Sep 17 00:00:00 2001 From: techniX Date: Sun, 8 Dec 2019 22:35:14 +0200 Subject: [PATCH] transmitter: better formspec validation --- transmitter.lua | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/transmitter.lua b/transmitter.lua index dd81c1b..9f3ce77 100644 --- a/transmitter.lua +++ b/transmitter.lua @@ -66,18 +66,29 @@ minetest.register_node("ham_radio:transmitter", { return end - local is_frequency_valid = ham_radio.validate_frequency(fields.frequency) - if is_frequency_valid.result == false then - ham_radio.errormsg(sender, is_frequency_valid.message) - return + local meta = minetest.get_meta(pos) + local transmitter_is_updated = false + + if fields.frequency ~= nil then + local is_frequency_valid = ham_radio.validate_frequency(fields.frequency) + if is_frequency_valid.result == false then + ham_radio.errormsg(sender, is_frequency_valid.message) + else + meta:set_string("frequency", fields.frequency) + transmitter_is_updated = true + end end - local meta = minetest.get_meta(pos) - meta:set_string("frequency", fields.frequency) - meta:set_string("rds_message", fields.rds_message) - ham_radio.transmitter_update_infotext(meta) - ham_radio.save_transmitter(pos, meta) - ham_radio.play_tuning_sound(sender) + if fields.rds_message ~= nil then + meta:set_string("rds_message", fields.rds_message) + transmitter_is_updated = true + end + + if transmitter_is_updated then + ham_radio.transmitter_update_infotext(meta) + ham_radio.save_transmitter(pos, meta) + ham_radio.play_tuning_sound(sender) + end end, can_dig = function(pos,player) local meta = minetest.get_meta(pos);