1. Hi All. I'm new here, and this is my first post. I just started going through the 2nd edition of WoW Programming, and having fun so far! I have 1 question regarding a line of code in BagBuddy, from page 198. Here's the code:

    -- If found, grab the item number and store the other data local itemNum = tonumber(link:match("|Hitem:(%d+):"))

    I understand the overall logic of the BagBuddy_Update() function, but that 2nd line I listed is tripping me up. It looks like this line is just getting the item number, but I don't understand how it's doing that. This line makes my eyes go crossed.

    Any chance of getting an explanation?

    Thanks!

    Hi All. I'm new here, and this is my first post. I just started going through the 2nd edition of WoW Programming, and having fun so far! I have 1 question regarding a line of code in BagBuddy, from page 198. Here's the code:

    -- If found, grab the item number and store the other data local itemNum = tonumber(link:match("|Hitem:(%d+):"))

    I understand the overall logic of the BagBuddy_Update() function, but that 2nd line I listed is tripping me up. It looks like this line is just getting the item number, but I don't understand how it's doing that. This line makes my eyes go crossed.

    If you read the section on the Lua standard libraries, it may explain it in further detail, but its taking the hyperlink string for the item, which looks like this:

     |cffa335ee|Hitem:47670:0:0:0:0:0:0:0:0:80|h[Idol of Lunar Fury]|h|r
    

    The item 'number' is the first number that appears after |Hitem, so we capture that using a pattern match using the string.match function. If you run the following:

    print(string.match("|cffa335ee|Hitem:47670:0:0:0:0:0:0:0:0:80|h[Idol of Lunar Fury]|h|r", "|Hitem:(%d+):"))

    you'll get 47670 (as a string) as the output. We then use the tonumber() function to convert that to a number. Does that make sense?