get_wield_list()

Kilarin
Member
 
Posts: 649
Joined: Mon Mar 10, 2014 00:36

get_wield_list()

by Kilarin » Sun Apr 20, 2014 02:03

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.
 

4aiman
Member
 
Posts: 1208
Joined: Mon Jul 30, 2012 05:47

Re: get_wield_list()

by 4aiman » Sun Apr 20, 2014 08:41

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)!
 

User avatar
Krock
Member
 
Posts: 3598
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker

Re: get_wield_list()

by Krock » Sun Apr 20, 2014 10:40

Kilarin wrote:get_inventory():get_width(player

4aiman wrote:get_inventory():get_size(player

Problem found
 

Kilarin
Member
 
Posts: 649
Joined: Mon Mar 10, 2014 00:36

Re: get_wield_list()

by Kilarin » Sun Apr 20, 2014 12:28

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.
 

Kilarin
Member
 
Posts: 649
Joined: Mon Mar 10, 2014 00:36

Re: get_wield_list()

by Kilarin » Fri May 23, 2014 15:26

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,
 

User avatar
Krock
Member
 
Posts: 3598
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker

Re: get_wield_list()

by Krock » Fri May 23, 2014 15:38

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.
Newest Win32 builds - Find a mod - All my mods
ALL YOUR DONATION ARE BELONG TO PARAMAT (Please support him and Minetest)
New DuckDuckGo !bang: !mtmod <keyword here>
 

Kilarin
Member
 
Posts: 649
Joined: Mon Mar 10, 2014 00:36

Re: get_wield_list()

by Kilarin » Fri May 23, 2014 15:44

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.
 

User avatar
Krock
Member
 
Posts: 3598
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker

Re: get_wield_list()

by Krock » Fri May 23, 2014 15:51

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)
Newest Win32 builds - Find a mod - All my mods
ALL YOUR DONATION ARE BELONG TO PARAMAT (Please support him and Minetest)
New DuckDuckGo !bang: !mtmod <keyword here>
 

4aiman
Member
 
Posts: 1208
Joined: Mon Jul 30, 2012 05:47

Re: get_wield_list()

by 4aiman » Sat May 24, 2014 18:36

Krock, "active slots", not "active slot". Otherwise helpful ;)
 

Kilarin
Member
 
Posts: 649
Joined: Mon Mar 10, 2014 00:36

Re: get_wield_list()

by Kilarin » Sun May 25, 2014 02:22

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?
 

User avatar
RealBadAngel
Member
 
Posts: 556
Joined: Wed Jul 18, 2012 16:30

Re: get_wield_list()

by RealBadAngel » Sun May 25, 2014 07:05

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.
 

Kilarin
Member
 
Posts: 649
Joined: Mon Mar 10, 2014 00:36

Re: get_wield_list()

by Kilarin » Sun May 25, 2014 12:58

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.
 


Return to Minetest Problems

Who is online

Users browsing this forum: Bing [Bot] and 21 guests