How to capture and store data (and view it via an alias)?

Vooku
Posts: 72
Joined: Sun Aug 21, 2016 2:42 pm

Re: How to capture and store data (and view it via an alias)?

Post by Vooku »

I get that just on the price. The other options work fine. I ran that lua command to convert but it didn't take I guess.

Vooku
Posts: 72
Joined: Sun Aug 21, 2016 2:42 pm

Re: How to capture and store data (and view it via an alias)?

Post by Vooku »

Oh, I haven't merged any files yet, so I'm thinking it's saving as a string still.

Vooku
Posts: 72
Joined: Sun Aug 21, 2016 2:42 pm

Re: How to capture and store data (and view it via an alias)?

Post by Vooku »

I removed the [[ and ]] from the numbers and it works fine. Could this be the issue causing my new data to be added as a string?

"price = tonumber(price)"

change to:

"price = tonumber(v.price)"

??

Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Re: How to capture and store data (and view it via an alias)?

Post by Jor'Mox »

Can I see that in context of all the code?

Vooku
Posts: 72
Joined: Sun Aug 21, 2016 2:42 pm

Re: How to capture and store data (and view it via an alias)?

Post by Vooku »

Code: [show] | [select all] lua
auction_data = auction_data or {}

function add_auction_data(item, price, buyer)
    local date = os.date("%b %d, %Y")
    price = tonumber(v.price)
    table.insert(auction_data,{item = item, price = price, buyer = buyer, date = date})
    table.save(getMudletHomeDir() .. "/auction_data.lua", auction_data)
end

function show_auction_data(sort_by)
    local sort_func
    sort_by = sort_by or "default"
    local sort_orders = {
        default = {'item','price','date'},
        date = {'date','item','price'},
        price = {'price','item','date'},
        buyer = {'buyer','item','date'},
    }
    local order = sort_orders[sort_by] or sort_orders.default
    
    sort_func = function (a,b)
            if a[ order[1] ] ~= b[ order[1] ] then return a[ order[1] ] < b[ order[1] ] end
            if a[ order[2] ] ~= b[ order[2] ] then return a[ order[2] ] < b[ order[2] ] end
            if a[ order[3] ] ~= b[ order[3] ] then return a[ order[3] ] < b[ order[3] ] end
            return false
        end
    table.sort(auction_data,sort_func)
    print(string.format("%-60s: %8s, %8s, %s", "ITEM", "PRICE", "DATE", "    BUYER"))
    for k,v in ipairs(auction_data) do
        print(string.format("%-60s: %8s, %8s, %s",v.item,v.price,v.date,v.buyer))
    end
end

if io.exists(getMudletHomeDir() .. "/auction_data.lua") and table.is_empty(auction_data) then
    table.load(getMudletHomeDir() .. "/auction_data.lua", auction_data)
end

Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Re: How to capture and store data (and view it via an alias)?

Post by Jor'Mox »

Yup. That is it. Just make that price instead of v.price and it should be good.

Vooku
Posts: 72
Joined: Sun Aug 21, 2016 2:42 pm

Re: How to capture and store data (and view it via an alias)?

Post by Vooku »

One small issue I am seeing. How can I get it to stop capturing my prompt at times? It doesn't do it often and I'm not sure what causes it.
Attachments
AucCapture.JPG
AucCapture.JPG (42.61 KiB) Viewed 5599 times
Last edited by Vooku on Fri Aug 03, 2018 10:08 pm, edited 1 time in total.

Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Re: How to capture and store data (and view it via an alias)?

Post by Jor'Mox »

Change your trigger pattern so that instead of starting like this: ^(.*)

It starts like this: Auction: (.*)

Vooku
Posts: 72
Joined: Sun Aug 21, 2016 2:42 pm

Re: How to capture and store data (and view it via an alias)?

Post by Vooku »

That didn't work for some reason. Changed to Auction: (.*) and it wouldn't capture. Right now my trigger is ^(.+)

Would there be an easy way to have it display how many items are in the table at the bottom of the print alias?

Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Re: How to capture and store data (and view it via an alias)?

Post by Jor'Mox »

To show how many items are in the list, do this: print(#auction_data)

As for the trigger, can you show me your full trigger pattern?

Post Reply