Adjustable Blinky Plant: fix very fast blinking before having set an interval + add a minimum interval setting

This commit is contained in:
upsilon 2017-05-21 19:11:12 +02:00
parent 17ddb23406
commit c53ac5b660
No known key found for this signature in database
GPG Key ID: A80DAE1F266E1C3C
4 changed files with 18 additions and 3 deletions

View File

@ -1,2 +1,3 @@
mesecons
moremesecons_utils
craft_guide?

View File

@ -4,7 +4,11 @@ local toggle_timer = function (pos, restart)
and not restart then
timer:stop()
else
timer:start(tonumber(minetest.get_meta(pos):get_string("interval")) or 0)
local interval = tonumber(minetest.get_meta(pos):get_string("interval")) or 1
if interval < moremesecons.setting("adjustable_blinky_plant", "min_interval", 0.5) then
interval = moremesecons.setting("adjustable_blinky_plant", "min_interval", 0.5)
end
timer:start(interval)
end
end
@ -30,7 +34,9 @@ mesecon.register_node("moremesecons_adjustable_blinkyplant:adjustable_blinky_pla
},
on_timer = on_timer,
on_construct = function(pos)
minetest.get_meta(pos):set_string("formspec", "field[interval;interval;${interval}]")
local meta = minetest.get_meta(pos)
meta:set_string("interval", "1")
meta:set_string("formspec", "field[interval;interval;${interval}]")
toggle_timer(pos, true)
end,
on_receive_fields = function(pos, _, fields, player)

View File

@ -13,7 +13,10 @@ function moremesecons.setting(modname, settingname, default, min)
return minetest.setting_get(setting) or default
elseif type(default) == "number" then
local ret = tonumber(minetest.setting_get(setting)) or default
if ret ~= ret then -- NaN
if not ret then
minetest.log("warning", "[moremesecons_"..modname.."]: setting '"..setting.."' must be a number. Set to default value ("..tostring(default)..").")
ret = default
elseif ret ~= ret then -- NaN
minetest.log("warning", "[moremesecons_"..modname.."]: setting '"..setting.."' is NaN. Set to default value ("..tostring(default)..").")
ret = default
end

View File

@ -1,3 +1,8 @@
[Adjustable Blinky Plant]
# Minimal interval authorized. Any lower will be set to it.
moremesecons_adjustable_blinky_plant.min_interval (Minimum Interval) float 0.5
[Craftable Commandblock]
# Space-separated list of authorized commands