[solved] minetest.setting_set not working?

User avatar
octacian
Member
 
Posts: 408
Joined: Mon Dec 21, 2015 22:18
GitHub: octacian
IRC: octacian
In-game: octacian

[solved] minetest.setting_set not working?

by octacian » Fri Jun 10, 2016 04:36

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?
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.
Last edited by octacian on Wed Jun 22, 2016 00:30, edited 1 time in total.
God isn't dead!

My Coolest Mods:
MicroExpansion, Working Computers, Interchangeable Hands

Check out my YouTube channel! (octacian)
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: minetest.setting_set not working?

by rubenwardy » Fri Jun 10, 2016 12:01

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

Note get not set
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 4 guests

cron