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

sorting system

Started by stabby, 11 January 2014 - 06:40 AM
stabby #1
Posted 11 January 2014 - 07:40 AM
Hello!

I started to work on a sorting system a few days back.

The idea is that you have a server computer that sends orders to a turtle that pick up stuff from barrels. That is already working, the problem i have now is the way to count every single item that comes to the system.

I'm using a interactive sorter. What it does is that it gives the Id and amount per stack that passes by. So if 32 cobblestone passed by it would say that 32 Cobblestone(in id form) just entered the system.


I'm not 100% sure on how to do the counting etc. What do you think would be the best choice for the server computer that counts items? (How i should code it? Creating a single file with a really large table inside?)

Here is the code for the storage server(The server that withdraws items) comp and the turtle(That withdraws items)

server http://pastebin.com/RZVgKdYJ

turtle http://pastebin.com/fZtVd0aE
Edited on 11 January 2014 - 06:41 AM
albrat #2
Posted 11 January 2014 - 07:57 AM
I would have a seperate computer that handles just the incoming items. Simply put send a message to the server computer that says "R 32 1" then have the server computer recieve the message, and store it in a table then send a "ack" response, to let the counter know that the message was recieved.

Where "R" is recieve. "32" is the count of items and "1" is the item number.

But I would store all incoming in a table, then just read from the table like a stack. That way you could send the information and store multiple entries before sending. fx. batch process several items then if idle for 2 seconds… Send data burst to the server.

I know I am not suggesting code but I hope this helps more with the idea stage. :)/>
stabby #3
Posted 11 January 2014 - 08:09 AM
I would have a seperate computer that handles just the incoming items. Simply put send a message to the server computer that says "R 32 1" then have the server computer recieve the message, and store it in a table then send a "ack" response, to let the counter know that the message was recieved.

Where "R" is recieve. "32" is the count of items and "1" is the item number.

But I would store all incoming in a table, then just read from the table like a stack. That way you could send the information and store multiple entries before sending. fx. batch process several items then if idle for 2 seconds… Send data burst to the server.

I was thinking about something like that. My other idea is that the counter gets for an example the id 7 and the amount 3. Then it checks if there is a file called 7 and if there is it adds 3 to the count. If there isnt a file called 7 it creates one and stores the value 3. Then when another computer asks "How much of the ID 7 do we have?" It returns with "3". That way the computer only work with ID's and never names.


Not sure if thats a good way to do it though
Edited on 11 January 2014 - 07:10 AM
albrat #4
Posted 11 January 2014 - 09:33 AM
It is a good way to do it, but I used a table system that used the id's as an index. eg table([7]) would give me the value 3. it does mean that every id would have to have a value. (not good for memory) But it means that checking the table for a id is easier on the programmer. But you could also store more information in the table. (table inside a table) …

I had a table setup of items(), items had a table inside each entry that had the quantity, name, max stack size. (not all items stack to 64) This meant if I wanted a Wooden Door, (324 or 64 item id.) I would check id 64, items([64](1)) – this would return eg. 32 (our stored quantity). items([64](2)) – This would return "Wooden Door", and items([64](3)) would return 16 as our max stack size.

** warning my information on how to do tables and the terminology may be wrong, I haven't worked with CC and tables for a while. (I've been on a hardmode server and its taken a month to setup a safe ish house.)


items = { [1] = { 0, "Stone" , 64 } ; [2] = { 0, "Grass" , 64 } ;
}
Edited on 11 January 2014 - 08:36 AM
santa22 #5
Posted 14 January 2014 - 07:35 PM
In one of my computercraft i had it detect if it picked up caticus or sugar cane, what i basically did was have it always have 1 of the item in inventory, and if it detected that there was more then 1, it would drop it, and display a message.

I imagine something similar could work here.
Bab #6
Posted 17 January 2014 - 01:19 AM
It wouldn't, unless you're only storing 16 kinds of items, which would make the whole system a little useless.
I personally save the amount in a file with the filename being the item ID.