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

Custom push events for wrapped computers

Started by Cranium, 18 June 2015 - 04:17 AM
Cranium #1
Posted 18 June 2015 - 06:17 AM
I'd like to have the ability to have a computer push a custom event to any other computer connected either by sitting next to it, or via wired modems. This would allow some additional communication between computers that are directly connected rather than relying on the more complex and sometimes more convoluted rednet/modem apis.

For example:
local computer = peripheral.wrap("right")
--# Listing the saved files on a connected computer
os.queueEvent("listFiles", computer)
--# Determining the type of computer without having to rely on a turtle.inspect() command
os.queueEvent("computerType", computer)

Better example thanks to Creator:

pc = peripheral.wrap(side)
pc.queueEvent(event,param1,param2,param3,...)

Basically, the first argument in os.queueEvent would be the event intended for queueing, and the second argument would be the wrapper to send that event to.
The first argument would be for the event to send, and the following arguments would just be the additional parameters to send. Even if the wrapped computer does not respond, the first computer's program would not halt, because all it is doing is sending an event to the computer next to it.

Anyone have thoughts on this idea?
Edited on 18 June 2015 - 01:33 PM
Lyqyd #2
Posted 18 June 2015 - 06:18 AM
Wouldn't such a suggestion make more sense as a peripheral method on the device?
Cranium #3
Posted 18 June 2015 - 06:21 AM
I'm not sure what you mean? Do you have an example?
Creator #4
Posted 18 June 2015 - 06:21 AM
Events may have more than one rerurn value. So, in my opinion it should be something like:

pc = peripheral.wrap(side)
pc.queueEvent(event,param1,param2,param3,...)

This is an example (we posted at the exact same time :P/>)
Edited on 18 June 2015 - 04:21 AM
Lyqyd #5
Posted 18 June 2015 - 06:22 AM
There's an example for you, Cranium. Another peripheral method, like the four they already offer.
Cranium #6
Posted 18 June 2015 - 06:24 AM
Yeah, that could work. Much cleaner than my example, for sure.
flaghacker #7
Posted 18 June 2015 - 08:52 AM
Yeah, that could work. Much cleaner than my example, for sure.

Might want to update the text in your first post too.