Page 1 of 1

get_wield_list()

PostPosted: Sun Apr 20, 2014 02:03
by Kilarin
When I try the following:
local gwl=player:get_inventory():get_width(player:get_wield_list())

I get back 0, which doesn't make any sense.

Re: get_wield_list()

PostPosted: Sun Apr 20, 2014 08:41
by 4aiman
Posted just to support this and tell that the latest Freeminer is affected too.
Moreover, local gwl=player:get_inventory():get_size(player:get_wield_list()) returns actual size (36 for me)!

Re: get_wield_list()

PostPosted: Sun Apr 20, 2014 10:40
by Krock
Kilarin wrote:get_inventory():get_width(player

4aiman wrote:get_inventory():get_size(player

Problem found

Re: get_wield_list()

PostPosted: Sun Apr 20, 2014 12:28
by Kilarin
4aiman wrote:get_inventory():get_size(player

How odd. This does give a work around, but it still seems that get_width is not behaving in an intuitive manner.

Re: get_wield_list()

PostPosted: Fri May 23, 2014 15:26
by Kilarin
So, is there no way to find out the width of the active inventory slots?
player:get_inventory():get_width(player:get_wield_list()) returns 0 (not useful)
gwl=player:get_inventory():get_size(player:get_wield_list()) returns 32 (the size of the entire inventory)

What I want is a way to find out that the inventory is 8 wide so that I know there are 8 active inventory slots. Is that possible?

Thanks,

Re: get_wield_list()

PostPosted: Fri May 23, 2014 15:38
by Krock
Well, I can't find any function to get this.
But why do you need this?
When you try to get the item outside of the itembar length, then it just takes it from the next inventory slot.

Re: get_wield_list()

PostPosted: Fri May 23, 2014 15:44
by Kilarin
Krock wrote:When you try to get the item outside of the itembar length, then it just takes it from the next inventory slot.

Yep. I don't need it for explorertools or bridgetool. I'm working on a variation of the compass mod and I would like to know if the compass is in the active inventory or not. When you take the compass out of the active slots, there is no need to be wasting cpu updating it. (Also, I turn off a hud update when the compass is no longer in the active slots)

Right now I've just got it hard coded to 8. But it would sure be nice to be able to determine what the inventory width really is, just in case another mod has modified it. I could do the total inventory width/4, but that isn't safe because a mod could always add or subtract a row.

Re: get_wield_list()

PostPosted: Fri May 23, 2014 15:51
by Krock
Kilarin wrote:
Krock wrote:When you try to get the item outside of the itembar length, then it just takes it from the next inventory slot.

Yep. I don't need it for explorertools or bridgetool. I'm working on a variation of the compass mod and I would like to know if the compass is in the active inventory or not. When you take the compass out of the active slots, there is no need to be wasting cpu updating it. (Also, I turn off a hud update when the compass is no longer in the active slots)

Right now I've just got it hard coded to 8. But it would sure be nice to be able to determine what the inventory width really is, just in case another mod has modified it. I could do the total inventory width/4, but that isn't safe because a mod could always add or subtract a row.

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
minetest.register_globalstep(function(dtime)
   for _, player in pairs(minetest.get_connected_players()) do
      if player:get_wielded_item():get_name() == "youritem" then
         update()
      end
   end
end)

Re: get_wield_list()

PostPosted: Sat May 24, 2014 18:36
by 4aiman
Krock, "active slots", not "active slot". Otherwise helpful ;)

Re: get_wield_list()

PostPosted: Sun May 25, 2014 02:22
by Kilarin
4aiman wrote: "active slots", not "active slot". Otherwise helpful ;)

So player:get_wielded_item():get_name() would only be getting items in the actual first wielded slot, right? Not any item in the first visible "active" row?

Re: get_wield_list()

PostPosted: Sun May 25, 2014 07:05
by RealBadAngel
Propably you need something like this:
https://github.com/minetest-technic/technic/blob/master/technic/tools/flashlight.lua#L33

That code checks if player is having flashlight in hotbar.

Re: get_wield_list()

PostPosted: Sun May 25, 2014 12:58
by Kilarin
RealBadAngel wrote:Propably you need something like this:

Thank you for the link, that is an excellent example of the problem. Notice the code:

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
local hotbar = inv:get_list("main")
for i = 1, 8 do


It's hard coded to check the first 8 inventory slots to see if the flashlight is in them. This is similar to how I am currently doing it. And it will work just fine with the default minetest gui. But, as 4aiman pointed out to me back when I was working on the explorertools mod, what if someone is using a mod that changes the inventory width? What if the server is running a mod that makes the inventory larger and the "hotbar" is now 9 across?
Thats why it would be handy to have a function that would tell me the width of the inventory so that I could determine within the program how wide the hotbar actually was instead of hardcoding it to 8.