Question

I'm trying to compare two tables I've created. The first table is always new with two or three items in it.

The table looks like this:

existingMTable = {}
local mTable = {}
local user = "me"

local function setupTable()
    local e = {}

    for i = 0, #totalusers do 
        e.secSinceMyEvent = GetTimeSinceEvent(i)
        e.timestamp = GetTimeStamp(i)
        e.seller = GetUserNames(i)

        of e.seller = "me" then
        table.insert(mTable, e)
        valueExists(mTable, e.timestamp)
    end
end

local function valueExists(tbl, value)

    for k,v in pairs(tbl) do
        if value ~= v then
            table.insert(existingMTable.History, value)

           print("value" .. value)
           print("v" .. v)
           print(existingMTable.History.timestamp)
        end
    end

    return false
end

I'm filtering out a huge list of people, I only want the items from 1 user. Once I have the few items, I want to add it to his sales history.

I need to compare the 3+ new items to his current table? by I believe the timestamp.

Was it helpful?

Solution

What you are doing does not make sense because second parameter to valueExists is a timestamp, which becomes "value" in valueExists, but in this function will be "e" type item. If I rename according to the way you call it and change some names so it is consistent, you would have something like:

local function valueExists(tbl, timestamp)

    for k,e in ipairs(tbl) do
        if timestamp ~= e.timestamp then
            table.insert(existingMTable.History, e)

            print("value" .. timestamp)
            print("e.timestamp" .. e.timestamp)
            #print(existingMTable.History.timestamp) -- WRONG because you inserted an e two lines above here
        end
    end

    return false
end

Now you can see the above does not make sense:

  • you are mixing "e" tables with timestamp values.
  • you are calling with the timestamp of last e added by setupTable, so valueExists will find the last item in table to have the searched timestamp

Take a look at the above: what are you actually try to do in that valueExists function?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top