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 » Sun Jul 29, 2018 2:50 pm

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 » Sun Jul 29, 2018 2:51 pm

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 » Sun Jul 29, 2018 7:44 pm

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: 1099
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 » Sun Jul 29, 2018 7:47 pm

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 » Mon Jul 30, 2018 1:03 am

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: 1099
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 » Mon Jul 30, 2018 1:05 am

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 » Fri Aug 03, 2018 10:06 pm

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 1228 times
Last edited by Vooku on Fri Aug 03, 2018 10:08 pm, edited 1 time in total.

Jor'Mox
Posts: 1099
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 » Fri Aug 03, 2018 10:07 pm

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 » Mon Aug 06, 2018 2:20 am

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: 1099
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 » Mon Aug 06, 2018 10:44 am

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

Who is online

Users browsing this forum: No registered users and 11 guests