This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
EarthwyrmJim's profile picture

Turtle Sorting Program Complications

Started by EarthwyrmJim, 23 April 2013 - 11:23 PM
EarthwyrmJim #1
Posted 24 April 2013 - 01:23 AM
Hey guys, I am working on a sorting program that will remove items from a designated "dump chest" and place them in the appropriate boxes. I'm using two mods to accomplish this:
OpenCCSensors v0.1.4c
Turtle Item Analyzer

There are three files I use:
sort - Does the physical sorting.
insert - Allows me to append to the item ID library.
ID.txt - Contains an entry for each of the items I have sorted thus far.

As of right now it works, but there are two things that I would really like to add and I don't know how to do it. I want to be able to search the ID.txt document and delete a line, so that I don't have to manually download the ID.txt file, edit it, and upload it to the turtle folder via FileZilla. The other thing is the ability to upload the ID.txt file to pastebin, or some other repository of some sort so I don't have to manually back up the file if necessary. I provided documentation on my program on the pastebin pages I linked.

The big issue I'm having is that there is no way to manipulate the file pointer when you're reading or writing lines. If I could manipulate the pointer and just write an empty line there, that would be good enough. However, there isn't a way for me to do that with the default FS API. The uploading of the ID.txt is just icing on the cake, really.

Any help or comments would be appreciated, about any aspect of the program.
EarthwyrmJim #2
Posted 24 April 2013 - 06:59 AM
Alright, so I got a working copy of a program to delete a line here. I have to copy the ID.txt file to a temp file (called ID) like I do in my insert program, and then when I copy the contents back, I exclude the line that I want to delete by using string.match(lineRead, substring_to_delete) as a criteria. It's a lot of copying, and I am unfortunately unaware of a more efficient way to do it. I'll have to work on it some more to get it nice and fancy, and eventually combine it all into one program.

As for uploading my ID.txt to some repository, I know I can use the http.post(website) method to upload my file. Fortunately I kept a copy of my ID.txt file on my desktop, because my delete function prototypes erased the contents of my ID.txt file… As of right now I update my programs by running a program to copy from pastebin (which is light years faster than before), so it's just a matter of figuring out how to upload now. Would anyone happen to know how I can do this?

Also, what do you guys think of the program in general? Anything I can improve on?

EDIT: I have some spare time on my hands before I need to go to school, so here's a screenshot of the system I set up. Items I want to sort go in the dump chest, then the turtle detects them, pulls them out, and sorts them. Anything not listed will go in the router, and be ejected by the turtle in 2 seconds if not routed. Items ejected from the router go into the Miscellaneous chest.