[solved] minetest.setting_set not working?

Post Reply
User avatar
octacian
Member
Posts: 597
Joined: Mon Dec 21, 2015 22:18
GitHub: octacian
IRC: octacian
In-game: octacian
Location: Canada

[solved] minetest.setting_set not working?

by octacian » Post

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?

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:

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.
Last edited by octacian on Wed Jun 22, 2016 00:30, edited 1 time in total.
MicroExpansion, Working Computers, All Projects - Check out my YouTube channel! (octacian)
I'm currently inactive in the Minetest community! So if I don't respond, that's why.

User avatar
rubenwardy
Moderator
Posts: 6978
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: minetest.setting_set not working?

by rubenwardy » Post

minetest.log("action", "[hud] hud_hotbar setting created, player's hotbars will be set to "..minetest.setting_get("hud_hotbar"))

Note get not set
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests