Posted 13 April 2013 - 08:28 AM
Hi guys, sorry this is the second topic I opened in few days, but I'm working at a big project (big for me,lol) and I'm encountering some problems every step.
So i'm working at a sorting sistem (with the Interactive sorter from Miscperipheral), and I'm trying to write a script for a menu with a search field to search, call and retrieve items.
So everytime I type for example "c", I want a list to appear of all items starting with the letter "c" and so on. And I want that lis to be in alphabetical order.
So this is What I wrote until now: http://pastebin.com/zjtyj7ue . It's obviously not finished yet, but i'm getting there.
My problem is with the alphaList() function, as I said I want the list to be in alphabetical order:
I'm trying to take elements from the nameList table (those are sorted for ID order, so [1]="Stone",[3]="Dirt",[4]="Cobblestone" etc.) and putting them in the alphaNameList table in alphabetical order.
I know there is a function in the table api (table.sort) and I read some info about it on the web, but because i'm still not to much an expert and because english = not nativeLanguage, I didn't understand how to use for this kind of situations.
So I tryed to go around the problem with this function.
Long story short, when I call this function the computer shuts down with no error message at all.
Any idea why? too many cycles? Did I totally misunderstood how "for k,v in pairs(table)" works? Is it a conspiracy? Am I going to survive the night? :P/>
thanks for the help :D/>
P.S. nameList contains about 100 elements and yes, I'm receiving correctly the table from rednet, I already tested it.
So i'm working at a sorting sistem (with the Interactive sorter from Miscperipheral), and I'm trying to write a script for a menu with a search field to search, call and retrieve items.
So everytime I type for example "c", I want a list to appear of all items starting with the letter "c" and so on. And I want that lis to be in alphabetical order.
So this is What I wrote until now: http://pastebin.com/zjtyj7ue . It's obviously not finished yet, but i'm getting there.
My problem is with the alphaList() function, as I said I want the list to be in alphabetical order:
function alphaList()
for k,v in pairs(nameList) do -- take every "v" one of the time from a table where items are in order of id
local inserted = false
if alphaNameList ~= {} then -- check if the table is empty i.e. nothing has been inserted yet
for key,vi in pairs(alphaNameList) do -- if is not empty for every "v" check every "vi" in the new table until it find one that is after in the alphabetical order and then put it one step down (key - 1)
if v < vi then
table.insert(alphaNameList,key - 1,v)
inserted = true
end
end
end
if inserted == false then -- if "v" is bigger of any "vi" or in the case table was empty, inserted is still false so it's going to simply put it at the end of the table
table.insert(alphaNameList,v)
end
end
end
I'm trying to take elements from the nameList table (those are sorted for ID order, so [1]="Stone",[3]="Dirt",[4]="Cobblestone" etc.) and putting them in the alphaNameList table in alphabetical order.
I know there is a function in the table api (table.sort) and I read some info about it on the web, but because i'm still not to much an expert and because english = not nativeLanguage, I didn't understand how to use for this kind of situations.
So I tryed to go around the problem with this function.
Long story short, when I call this function the computer shuts down with no error message at all.
Any idea why? too many cycles? Did I totally misunderstood how "for k,v in pairs(table)" works? Is it a conspiracy? Am I going to survive the night? :P/>
thanks for the help :D/>
P.S. nameList contains about 100 elements and yes, I'm receiving correctly the table from rednet, I already tested it.