[solved] minetest.setting_set not working?
I'm in the midst of editing the HUD mod by BlockMen, giving more hotbar options as well as a better inventory. The problem is, that somehow the setting that defines the default hotbar (default) isn't registering. The if statement checks if the setting hud_hotbar exists (I think it does anyway), and if it doesn't creates the setting, printing one of two things to the log. This isn't necessarily a problem, as the proper hotbar is used due to the next if statement, but the setting doesn't seem to be read either meaning I can't change to another hotbar.
Problematic if statement?
Full code in init.lua:
Thanks, help would be really appreciated. The full code is available through my fork on Github. The specific code above isn't there though, as well as modifications to api.lua, as I don't want to commit my changes till they are functional.
Problematic if statement?
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
if minetest.setting_get("hud_hotbar") then
minetest.log("action", "[hud] Player's hotbars will be set to "..minetest.setting_get("hud_hotbar"))
else
minetest.setting_set("hud_hotbar", "default")
minetest.log("action", "[hud] hud_hotbar setting created, player's hotbars will be set to "..minetest.setting_set("hud_hotbar", "default"))
end
Full code in init.lua:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
hud = {}
local modpath = minetest.get_modpath("hud")
dofile(modpath .. "/api.lua")
dofile(modpath .. "/functions.lua")
dofile(modpath .. "/builtin.lua")
dofile(modpath .. "/legacy.lua")
-- hotbar settings
-- check if hotbar setting exists, else create it
if minetest.setting_get("hud_hotbar") then
minetest.log("action", "[hud] Player's hotbars will be set to "..minetest.setting_get("hud_hotbar"))
else
minetest.setting_set("hud_hotbar", "default")
minetest.log("action", "[hud] hud_hotbar setting created, player's hotbars will be set to "..minetest.setting_set("hud_hotbar", "default"))
end
--variables
hud.hotbar_type = minetest.setting_get("hud_hotbar")
hud.item_wheel = minetest.setting_getbool("hud_item_wheel")
-- check hotbar setting
minetest.register_on_joinplayer(function(player)
if hud.hotbar_type == "default" then
-- [default] 9 item hotbar (default)
minetest.after(0.5, function()
minetest.after(0, player.hud_set_hotbar_itemcount, player, 9) -- set hotbar size
player:hud_set_hotbar_image("hud_hotbar_default.png")
player:hud_set_hotbar_selected_image("hud_hotbar_selected_default.png")
end)
elseif hud.hotbar_type == "hud" then
-- [hud] original hotbar for hud by BlockMen
minetest.after(0.5, function()
minetest.after(0, player.hud_set_hotbar_itemcount, player, 8) -- set hotbar size
player:hud_set_hotbar_image("hud_hotbar_hud.png")
player:hud_set_hotbar_selected_image("hud_hotbar_selected_hud.png")
end)
elseif hud.hotbar_type == "itemwheel" or minetest.setting_getbool("hud_item_wheel") == true then
-- [itemwheel] itemwheel hotbar by BlockMen
minetest.setting_set("hud_hotbar", "itemwheel")
dofile(modpath .. "/itemwheel.lua")
elseif hud.hotbar_type == "minetest" then
-- [minetest] default minetest hotbar
minetest.after(0.5, function()
minetest.after(0, player.hud_set_hotbar_itemcount, player, 8) -- set hotbar size
player:hud_set_hotbar_image("hud_hotbar_minetest.png")
player:hud_set_hotbar_selected_image("hud_hotbar_selected_minetest.png")
end)
else
-- [default] 9 item hotbar (default)
minetest.after(0.5, function()
minetest.setting_set("hud_hotbar", "default")
minetest.after(0, player.hud_set_hotbar_itemcount, player, 9) -- set hotbar size
player:hud_set_hotbar_image("hud_hotbar_default.png")
player:hud_set_hotbar_selected_image("hud_hotbar_selected_default.png")
end)
end
end)
Thanks, help would be really appreciated. The full code is available through my fork on Github. The specific code above isn't there though, as well as modifications to api.lua, as I don't want to commit my changes till they are functional.