Page 5 of 8

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

Posted: Fri Jul 27, 2018 9:02 pm
by Vooku
I paste/copied your newest code in and here a screen shot of the print data when I "@aucdata price"

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

Posted: Fri Jul 27, 2018 9:35 pm
by Vooku
Maybe my .lua file is the issue.

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

Posted: Fri Jul 27, 2018 9:38 pm
by Jor'Mox
I'm assuming that is after you ran the code snippet to switch all the prices from strings to numbers, though that isn't sorting by price in either paradigm. So, the problem is likely in your alias, combined with the fact that the function we are using checks for the exact text. Can you copy your alias pattern and code here, and at the bottom of the code for the alias, can you add this: display(matches)

Hopefully that will let us see what is actually getting sent to the function, so we can understand why it is working the way it is.

Edit: Just looked at your Lua file, and it seems fine, though I can tell the prices are still stored as strings.

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

Posted: Fri Jul 27, 2018 9:43 pm
by Vooku
I ran the LUA script you posted to convert to number. Not sure why it didn't work.

@aucdata(?: \w+)?$

show_auction_data(matches[2])

display(matches) returns "@aucdata price"

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

Posted: Fri Jul 27, 2018 9:47 pm
by Jor'Mox
Okay, so I'm not sure how much of those problems are down directly to me... but, your alias pattern is the problem. It should be this: ^@aucdata(?: (\w+))?$

Without that extra set of parentheses nothing was getting captured, and hence nothing got passed to the show_auction_data function.

Running the script snippet would convert the data in the table, but the changes don't get saved until more data is added when a new auction is captured (though you could just use the table.save line from the function to save it manually).

Edit: If prices are still actually strings, then when you sort by price they will be sorted so that all prices starting with a 1 come first, followed by those starting with a 2, etc. If they are numbers, then we all know how that should look.

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

Posted: Fri Jul 27, 2018 9:50 pm
by Vooku
That was it! Working now. I thought I copied the capture alias. Somehow I messed it up. Thanks, sorting working!

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

Posted: Sat Jul 28, 2018 11:20 am
by Vooku
Hate to bug you again... I have two questions.

How could I manually add an item (item, price, date, buyer) myself via an 'lua' command?

Also, would it be a pain to merge auction_data.lua files? I play on my laptop and my tablet so I'd like to be able to merge the table from my tablet to my laptop table. Guessing that isn't as easy.

I really appreciate the help!

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

Posted: Sat Jul 28, 2018 12:14 pm
by Jor'Mox
If you really care about the date, the. I would do it this way: lua table.insert(auction_data,{item = “item name”, price = 100, date = “Jul 27, 2018”, buyer = “buyer name”})

As for merging files, obviously the first step is to put a copy of the second file in the same folder as the file you want to merge it with, with a slightly changed name. Then you want to load that file into a table, merge that table with the auction_data table, and then save the auction_data table. Sort of like this:
Code: [show] | [select all] lua
local tmp = {}
table.load(getMudletHomeDir()..”file.lua”,tmp)
auction_data = table.n_union(auction_data,tmp)
table.save(getMudletHomeDir() .. “auction_data.lua”,auction_data)[\lua]

Key sidenote. I wrote this on my phone, so extra double check for errors and typos.

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

Posted: Sun Jul 29, 2018 1:15 pm
by Vooku
I'm getting an "attempt to compare number with string" error on @aucdata price. Is that because I'm not storing price number?

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

Posted: Sun Jul 29, 2018 1:21 pm
by Jor'Mox
That is because some are strings and some are numbers. Though lua shouldn’t struggle to compare “10” and 10, as it can convert back and forth fairly easily. Do you get this sort of error with any other sorting, or just price? And if you can see all your data, do any of the prices look like they aren’t numbers? If not, you probably need to convert all the prices to numbers again, and then save the table.

My guess would be that when you merged the two files, one file had strings while the other had numbers.