Thread Tools Display Modes
05-15-18, 06:17 AM   #1
saxitoxin
A Theradrim Guardian
 
saxitoxin's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 60
getting bagslots from the tooltip

Unless there is a function where I can get the total number of slots in a bag that is in my inventory (not equipped)

My guess is that I have to scan the tooltip, but I have no idea how to do that

I know that
Code:
CONTAINER_SLOTS = "%d Slot %s";
is the line in the tooltip

but not how to get %d as a value from that line in the tooltip

I would appreciate a sample code
  Reply With Quote
05-15-18, 07:05 AM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,877
I couldn't see anything specific, so hopefully someone better versed in this area will pipe in at some point, but this might be one way of getting the info you need.

Get the item in the tooltip
https://wow.gamepedia.com/API_GameTooltip_GetItem

Use the item link return value
https://wow.gamepedia.com/ItemLink

Then see what the different values are in the itemString relating to the item
https://wow.gamepedia.com/ItemString

Hopefully one of those values will be the bag quantity, trial and error will obviously be the key
__________________
  Reply With Quote
05-15-18, 07:06 AM   #3
d87
A Chromatic Dragonspawn
 
d87's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 163
Lua Code:
  1. -- Construct your saarch pattern based on the existing global string:
  2. local S_ITEM_LEVEL   = "^" .. gsub(ITEM_LEVEL, "%%d", "(%%d+)")
  3. local strmatch = string.match
  4.  
  5. -- Create the tooltip:
  6. local scantip = CreateFrame("GameTooltip", "MyScanningTooltip", nil, "GameTooltipTemplate")
  7. scantip:SetOwner(UIParent, "ANCHOR_NONE")
  8.  
  9. local function GetItemLevelFromTooltip(itemLink)
  10.     -- Pass the item link to the tooltip:
  11.     scantip:SetHyperlink(itemLink)
  12.  
  13.     -- Scan the tooltip:
  14.     for i = 2, scantip:NumLines() do -- Line 1 is always the name so you can skip it.
  15.         local text = _G["MyScanningTooltipTextLeft"..i]:GetText()
  16.         if text and text ~= "" then
  17.         local itemLevel = strmatch(text, S_ITEM_LEVEL)
  18.             if itemLevel then
  19.                 return itemLevel
  20.             end
  21.         end
  22.     end
  23. end
  Reply With Quote
05-15-18, 07:33 AM   #4
saxitoxin
A Theradrim Guardian
 
saxitoxin's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 60
I might get some of the info i need from getItemString

--

Yes d87 i was thinking of a function like this but for bagslots and not Ilvl but i have no idea what the gsub is suppose to look like
  Reply With Quote
05-15-18, 07:45 AM   #5
d87
A Chromatic Dragonspawn
 
d87's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 163
local pattern = "^" .. CONTAINER_SLOTS:gsub("%%d", "(%%d+)"):gsub("%%s", ".+")
  Reply With Quote
05-15-18, 08:53 AM   #6
saxitoxin
A Theradrim Guardian
 
saxitoxin's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 60
I can't test this yet, but can you please eli5 what this means?
From what i have read %d is number, %s is string but why use %%d?

Last edited by saxitoxin : 05-15-18 at 08:54 AM. Reason: autocorrect
  Reply With Quote
05-15-18, 09:00 AM   #7
runamonk
A Theradrim Guardian
 
runamonk's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 61
Originally Posted by saxitoxin View Post
I can't test this yet, but can you please eli5 what this means?
From what i have read %d is number, %s is string but why use %%d?
If you want to output/match a literal % you need to double it up so that the interpreter knows, otherwise it assumes you want to format that character or string.

Check this out

Last edited by runamonk : 05-15-18 at 09:03 AM.
  Reply With Quote
05-15-18, 03:37 PM   #8
saxitoxin
A Theradrim Guardian
 
saxitoxin's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 60
Thank you!

Got it working!


Guess I have to read up on stringformating and those stuffs now
  Reply With Quote
05-15-18, 04:58 PM   #9
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,877
Congratulations ... because Grats isn't long enough
__________________
  Reply With Quote
05-15-18, 05:42 PM   #10
JDoubleU00
A Firelord
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 463
Originally Posted by Xrystal View Post
Congratulations ... because Grats isn't long enough
Congo Rats!
__________________
Author of JWExpBar and JWRepBar.
  Reply With Quote
05-16-18, 12:46 AM   #11
runamonk
A Theradrim Guardian
 
runamonk's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 61
Congrats! Always awesome when a plan comes together.
  Reply With Quote
05-19-18, 01:04 PM   #12
Kakjens
A Cliff Giant
Join Date: Apr 2017
Posts: 75
Before printing you might want to sort the suggestions in, for example, descending benefit.
How should your addon treat profession bags? What about bags that are in (or for) bank?
  Reply With Quote
05-21-18, 12:56 AM   #13
saxitoxin
A Theradrim Guardian
 
saxitoxin's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 60
thank you all!

I really appreciate suggestions
This is only meant for personal use now. The addon tells me if I have gotten any better gear, a bigger bag or new transmog gear
As of now it only check the 0-4 slots of the inventory, and only for the subtype "Bag"
But I might add this in if/after a public release
I have no idea how the addon will work with other languages than English either
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » getting bagslots from the tooltip

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off