Thread Tools Display Modes
10-28-16, 07:14 PM   #1
Twitchy250
A Deviate Faerie Dragon
Join Date: Aug 2016
Posts: 14
Dictionary-Attempt to Index Field ? a Nil Value help

Hello WoW Interface,

I have been working on a simple AH analytics Addon and requires a bit of a bulky dictionary and have not worked with dictionaries outside of php (which has been a while).

The way I am trying to lay out the dictionary is UrchinDictionary as the primary dictionary table with the key [1] holding a setting determining the number of snapshots of the AH to hold and [2]-[3]-[4] ect holding each snapshot.

Because each snapshot can contain a lot of info on a single item due to multiple listings, it makes it a little more complicated. (reading the dictionary to me is the easy part)

I have successfully pulled data from the AH and input listings into a table, but not completely having my head wrapped around a dictionary is giving me some complications.

NOTE: some variables still have to be edited to become local variables

I believe this is all the code neccessary to show:

Code:
--UrchinDictionary is a saved variable that is working properly when adding records to a simple table

DictionaryFix = {}      -- A Dictionary to store multiple records, and then slipped into UrchinDictionary[x] (UrchinDictionary[1] holds the number of dictionaries to hold)
DictionaryFixOne = 0  --haven't thought of a better name for these variables yet

function UrchinReadAH()
  --print("Reading AH");
    local totalAuctions
    local UrchinCounterOne, UrchinCounterTwo
    --local DictionaryFixOne=0
    numBatchAuctions, totalAuctions = GetNumAuctionItems("list") --numBatchAuctions, MaxAuctions = GetNumAuctionItems("list") --_,MaxAuctions = GetNumAuctionItems("list")
    for tableloop=1,totalAuctions do
          name, texture, count, quality, canUse, level, levelColHeader, minBid, minIncrement, buyoutPrice, bidAmount, highBidder, bidderFullName, owner, ownerFullName, saleStatus, itemId, hasAllInfo = GetAuctionItemInfo("list", 1) --name, texture, count, quality, canUse, level, minBid, minIncrement, buyoutPrice, bidAmount, highestBidder, owner, sold=GetAuctionItemInfo("list",tableloop)
          DictionaryFix[DictionaryFixOne+1][1]=name;    --UrchinDictionary[#UrchinDictionary+1]=name
          DictionaryFix[DictionaryFixOne+1][2]=texture
          DictionaryFix[DictionaryFixOne+1][3]=count
          DictionaryFix[DictionaryFixOne+1][4]=quality
          DictionaryFix[DictionaryFixOne+1][5]=canUse
          DictionaryFix[DictionaryFixOne+1][6]=level
          DictionaryFix[DictionaryFixOne+1][7]=levelColHeader
          DictionaryFix[DictionaryFixOne+1][8]=minBid
          DictionaryFix[DictionaryFixOne+1][9]=minIncrement
          DictionaryFix[DictionaryFixOne+1][10]=buyoutPrice
          DictionaryFix[DictionaryFixOne+1][11]=bidAmount
          DictionaryFix[DictionaryFixOne+1][12]=highBidder
          DictionaryFix[DictionaryFixOne+1][13]=bidderFullName
          DictionaryFix[DictionaryFixOne+1][14]=owner
          DictionaryFix[DictionaryFixOne+1][15]=ownerFullName
          DictionaryFix[DictionaryFixOne+1][16]=saleStatus
          DictionaryFix[DictionaryFixOne+1][17]=itemId
          DictionaryFix[DictionaryFixOne+1][18]=hasAllInfo
          --print(name);
          DictionaryFixOne=DictionaryFixOne+1
    end
    --local UrchinNumRecords=UrchinDictionary[1]
    UrchinDictionary[2]=DictionaryFix
    --return DictionaryFix
end
I am trying to use the DictionaryFixOne variable to determine DictionaryFix[x], each time the for loop loops to increment by one so DictionaryFix[1] becomes DictionaryFix[2] the next time around

And on top of my issue with the getting the dictionary to work, because a simple AH search can result in multiple listings, the code above is assuming there will only be one listing

Any help is greatly appreciated! Thank you all in advanced
  Reply With Quote
10-28-16, 09:20 PM   #2
Twitchy250
A Deviate Faerie Dragon
Join Date: Aug 2016
Posts: 14
I guess to simplyfy things I'm asking if someone could give an example of how to properly create a dictionary, or put arrays inside another array
  Reply With Quote
10-28-16, 10:04 PM   #3
Ketho
A Pyroguard Emberseer
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,026
Lua tables can be used as both indexed and associative arrays
(if that's what you mean with dictionaries)

https://www.lua.org/pil/2.5.html -- Tables
http://www.lua.org/pil/11.2.html -- Matrices and Multi-Dimensional Arrays

Here are 2 examples of associative tables
Lua Code:
  1. local myTable = {
  2.     India = "juliet",
  3.     alpha = "bravo",
  4.     echo = "foxtrot",
  5.     Charlie = "delta",
  6.     golf = "hotel",
  7. }
  8.  
  9. local someTable = {}
  10. someTable.foo = "hello"
  11. someTable["bar"] = 123
  12. someTable[7] = "world"

Another 2 examples of a multidimensional array/table
Lua Code:
  1. -- sequential/index keys can be ommitted in this case but just an example
  2. local myTable = {
  3.     [1] = {1, 2, 3},
  4.     [2] = {1, 2, 3},
  5.     [3] = {1, 2, 3},
  6.     [4] = {1, 2, 3},
  7. }
  8.  
  9. local someTable = {}
  10.  
  11. for i = 1, 4 do
  12.     someTable[i] = {}
  13.     for j = 1, 3 do
  14.         someTable[i][j] = j
  15.     end
  16. end

Originally Posted by Twitchy250 View Post
The way I am trying to lay out the dictionary is UrchinDictionary as the primary dictionary table with the key [1] holding a setting determining the number of snapshots of the AH to hold and [2]-[3]-[4] ect holding each snapshot.

Because each snapshot can contain a lot of info on a single item due to multiple listings, it makes it a little more complicated. (reading the dictionary to me is the easy part)

Looking at your code I would rewrite it like this (untested),
but I honestly... can't understand what you're trying to do so there's probably a better way to do this :S
Lua Code:
  1. local dictionaryFix = {}
  2.  
  3. local function ReadAH()
  4.     local _, totalAuctions = GetNumAuctionItems("list")
  5.     for i = 1, totalAuctions do -- sorry for wasting tables
  6.         dictionaryFix[i] = {GetAuctionItemInfo("list", i)}
  7.     end
  8. end

(edit) wait, why couldn't you just continue in your previous thread? :x
http://www.wowinterface.com/forums/s...ad.php?t=54731

Last edited by Ketho : 10-29-16 at 02:24 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Dictionary-Attempt to Index Field ? a Nil Value help

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