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

Input from several turtles

Started by Skeggiold, 15 May 2014 - 07:32 PM
Skeggiold #1
Posted 15 May 2014 - 09:32 PM
I have an ender quarry running and a friend of mine has a Digital Miner, and yet another has a MFR Mining Laser running. So we wanted to do a little competition to see who has the best net result of ores. This sprung the idea of writing a program which keeps track of what has been mined by each machine and displays this on a monitor.

The way I envisioned doing this is to have each machine output to a chest, have a turtle monitor the contents of said chest then placing the contents in another chest which will be picked up by the AE network.

Now in my main program, I thought about doing something along these lines:


while true do
event, ID, message, dist = os.pullEvent('rednet_message')
processInput(ID, message)
end

But what happens if I get a message from the Ender Quarry Turtle, and while I'm processing this message, the MFR Mining Laser Turtle sends me another message. Will this get lost? Or will all messages be queued and eventually picked up when someone calls for a pullEvent('rednet_message')?
Alternatively, is there a more elegant way of doing this?
Lyqyd #2
Posted 15 May 2014 - 10:05 PM
Events are queued and will only be pulled from the queue as your code requests them. Be aware that a variety of calls will pull events from the queue (such as sleep, read, rednet.receive, etc.) until they get events that they are looking for. The code you have there looks fine as long as the function you plan to call doesn't include any calls to functions that also pull events.
KingofGamesYami #3
Posted 15 May 2014 - 10:06 PM
Personally, I would use the modem api instead. Have each turtle listening on only one channel, and the main program listen on all channels.
CometWolf #4
Posted 15 May 2014 - 10:06 PM
The messages will be queued, and the information is probably processed so fast you wouldn't miss it anyways. I fail to see the point of the turtle though. Assuming you're using openP to identify the items anyways, you might aswell use that to extract to the AE network directly aswell.
Edited on 15 May 2014 - 08:06 PM
Skeggiold #5
Posted 16 May 2014 - 05:49 PM
The messages will be queued, and the information is probably processed so fast you wouldn't miss it anyways. I fail to see the point of the turtle though. Assuming you're using openP to identify the items anyways, you might aswell use that to extract to the AE network directly aswell.

I'm not sure how you would do this with OpenPeripherals. I'm fairly new to the mod and looking at the items it provides I wouldn't know which one fits my needs exactly. The main reason I'm using a turtle is to be sure that I pick the item up before checking how much I've picked up, to give an accurate quantity back to the main program.

Personally, I would use the modem api instead. Have each turtle listening on only one channel, and the main program listen on all channels.

The turtles only send directly to the terminal, the terminal listens for any rednet message it receives then processes this and shows the results on the monitor.

—-

I have another issue now though, however. It seems calling getStackInSlot(slotID) doesn't always give a friendly name of the item. Is there another way to get metadata from an item? I currently have no access to OpenCCSensors, I'm using the TPPI modpack.
apemanzilla #6
Posted 16 May 2014 - 08:26 PM
The messages will be queued, and the information is probably processed so fast you wouldn't miss it anyways. I fail to see the point of the turtle though. Assuming you're using openP to identify the items anyways, you might aswell use that to extract to the AE network directly aswell.

I'm not sure how you would do this with OpenPeripherals. I'm fairly new to the mod and looking at the items it provides I wouldn't know which one fits my needs exactly. The main reason I'm using a turtle is to be sure that I pick the item up before checking how much I've picked up, to give an accurate quantity back to the main program.

Personally, I would use the modem api instead. Have each turtle listening on only one channel, and the main program listen on all channels.

The turtles only send directly to the terminal, the terminal listens for any rednet message it receives then processes this and shows the results on the monitor.

—-

I have another issue now though, however. It seems calling getStackInSlot(slotID) doesn't always give a friendly name of the item. Is there another way to get metadata from an item? I currently have no access to OpenCCSensors, I'm using the TPPI modpack.
Yes,open peripheral has problems with localization. Unfortunately, this is not an issue that can be easily resolved. You can use the ID and damage value to (usually) separate different item stacks, but you cannot read item metadata.