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

rednet control of a sorting system

Started by plazter, 05 December 2012 - 02:31 AM
plazter #1
Posted 05 December 2012 - 03:31 AM
Heya guys! ;)/>

so, i want to make a little system with computers + engines to pull out of barrels all after what i ask it for,
i cant remember how the code is for the receiver computer to read what i text to it.
-i have been looking around the forum for quite some time now and i didnt really find any
could u guys help me please? :)/>

Regard Plazter
OmegaVest #2
Posted 05 December 2012 - 04:49 AM
Wiki. I suggest you go look here, specifically the APIs page. Also, the Lua Manual has a lot of good information.
plazter #3
Posted 05 December 2012 - 05:47 AM
im a noob, but i've been searching again
came up with this but aint working (im a complete noob :P/>)

rednet.open("left")
rednet.receive()
m = os.pullEven()
if m then
rs.setOutput("top", true)
end
OmegaVest #4
Posted 05 December 2012 - 05:59 AM
First, it's os.pullEvent()

Second, what exactly are you trying to do here? If you are trying to get it to change the state of redstone upon any input to the computer, then you are on the right track.


Oh, and if you have os.pullEvent, you don't need rednet.receive. Either one will grab rednet messages, but both will just cause the program to stop and wait for a second message.
plazter #5
Posted 05 December 2012 - 06:01 AM
what im trying to do is makeing a server up in my main room that can send a number wich will start an engine down the storage room and will travel it up in a chest :s thats all im trying :P/>

edit: DURH! didnt notice that :D/>
Said otherwise, i wish to be able to send a rednet message with the word "on", and the other computer that receives will turn on the redstone to the engine :)/>
ChaddJackson12 #6
Posted 05 December 2012 - 06:44 AM
On computer that sends:

Filename: startup

rednet.open("side") -- Edit this

term.clear()
term.setCursorPos(1,1)
print("Turn rednet computer on or off?")
write("\n> ")
status = read()
if status == "On" or status == "on" then
  rednet.send(ID, "on") -- Edit this too
  print("\nRednet Computer Has Been Turned On!")
  os.sleep(2)
  os.reboot()
elseif status == "Off" or status == "off" then
  rednet.send(ID, "off") -- Edit this also
  print("\nRednet Computer Has Been Turned Off!")
  os.sleep(2)
  os.reboot()
end

On the computer that receives:

Filename: startup

rednet.open("side") -- Edit this

term.clear()
term.setCursorPos(1, 1)
print("Listening For Commands...")
while true do
  ID, status = rednet.receive()
  if status == "on" then
	print("Redstone Has Been Turned On!")
	rs.setOutput("side", true) -- Edit this too
  elseif status == "off" then
	print("Redstone Has Been Turned Off!")
	rs.setOutput("side", false) -- Edit this also
  end
end

I hope this is what you were looking for, and if it is, then there you go.
plazter #7
Posted 05 December 2012 - 07:02 AM
On computer that sends:

Filename: startup

rednet.open("side") -- Edit this

term.clear()
term.setCursorPos(1,1)
print("Turn rednet computer on or off?")
write("\n> ")
status = read()
if status == "On" or status == "on" then
  rednet.send(ID, "on") -- Edit this too
  print("\nRednet Computer Has Been Turned On!")
  os.sleep(2)
  os.reboot()
elseif status == "Off" or status == "off" then
  rednet.send(ID, "off") -- Edit this also
  print("\nRednet Computer Has Been Turned Off!")
  os.sleep(2)
  os.reboot()
end

On the computer that receives:

Filename: startup

rednet.open("side") -- Edit this

term.clear()
term.setCursorPos(1, 1)
print("Listening For Commands...")
while true do
  ID, status = rednet.receive()
  if status == "on" then
	print("Redstone Has Been Turned On!")
	rs.setOutput("side", true) -- Edit this too
  elseif status == "off" then
	print("Redstone Has Been Turned Off!")
	rs.setOutput("side", false) -- Edit this also
  end
end

I hope this is what you were looking for, and if it is, then there you go.

- Yes it exactly what i was looking for ;D tho where it is say "on" at computer, how can i change it so that if i want.. lets take iron.. and then type iron would that be easy to change?

Edit: the main computer will end up sending to multiple computers btw :P/>
OmegaVest #8
Posted 05 December 2012 - 07:44 AM
EDIT: Whoops. Neglected first post. Ignore this for a moment.



EDIT2: Okay. So, first things first, you're gonna need to find the ids of the receiver computers. That's fairly easy, on the shell, just type id, and it will bring it up. Now, since I assume you are using a sorting system wherein each chest is filled with exactly one type of item, and there is one computer per chest (or close to it), it is not hard at all to change it to suit.

However, it will take time mostly because you need to know what computer does what, but here's my modifications to make it work with Chadd's code.

On the sender computer:



chestComps = {
   ["iron"] = ##,  -- Make this the computer id for iron
   ["cobble"] = ##,  -- Make this the computer id for cobblestone.
	 -- Add more computer ids and item keys here, so they match this format
   ["item name"] = compID
}

rednet.open("side") -- Edit this

term.clear()
term.setCursorPos(1,1)
print("Access which item's computer?")
write("\n> ")
id = tolower(read())
print("Turn computer on or off?")
write("\n> ")
status = read()
if status == "On" or status == "on" then
  rednet.send(chestComps[id], "on")
  print("\nRednet Computer for Item \"", id, "\" Has Been Turned On!")
  os.sleep(2)
  os.reboot()
elseif status == "Off" or status == "off" then
  rednet.send(chestComps[id], "off") -- Edit this also
  print("\nRednet Computer for Item \"", id, "\" Has Been Turned Off!")
  os.sleep(2)
  os.reboot()
end



And this is a very sloppy mod, but it should work. Also, the receiver code does not need to change.
plazter #9
Posted 05 December 2012 - 08:29 AM
thanks alot :)/>
plazter #10
Posted 05 December 2012 - 08:55 AM
EDIT: Whoops. Neglected first post. Ignore this for a moment.



EDIT2: Okay. So, first things first, you're gonna need to find the ids of the receiver computers. That's fairly easy, on the shell, just type id, and it will bring it up. Now, since I assume you are using a sorting system wherein each chest is filled with exactly one type of item, and there is one computer per chest (or close to it), it is not hard at all to change it to suit.

However, it will take time mostly because you need to know what computer does what, but here's my modifications to make it work with Chadd's code.

On the sender computer:



chestComps = {
   ["iron"] = ##,  -- Make this the computer id for iron
   ["cobble"] = ##,  -- Make this the computer id for cobblestone.
	 -- Add more computer ids and item keys here, so they match this format
   ["item name"] = compID
}

rednet.open("side") -- Edit this

term.clear()
term.setCursorPos(1,1)
print("Access which item's computer?")
write("\n> ")
id = tolower(read())
print("Turn computer on or off?")
write("\n> ")
status = read()
if status == "On" or status == "on" then
  rednet.send(chestComps[id], "on")
  print("\nRednet Computer for Item \"", id, "\" Has Been Turned On!")
  os.sleep(2)
  os.reboot()
elseif status == "Off" or status == "off" then
  rednet.send(chestComps[id], "off") -- Edit this also
  print("\nRednet Computer for Item \"", id, "\" Has Been Turned Off!")
  os.sleep(2)
  os.reboot()
end



And this is a very sloppy mod, but it should work. Also, the receiver code does not need to change.

"startup:14: attemp to call nill" ;s ID is the computer i send 2 right?
OmegaVest #11
Posted 05 December 2012 - 09:03 AM
Ah, I see the problem, which came from Chadd's code, I think. Change both write() calls to term.write(). I think that is the problem.

And yes, the id is the computer that you are attempting to send to. However, attempt to call nill is a problem where the computer does not understand what function you are trying to use , like if you mispell its name, or forget to put its api on the front of it (as here).
plazter #12
Posted 05 December 2012 - 09:10 AM
now that i made the change in line 14 to
"23 = tolower(read())"
its not able 2 start ;S
DaWooShit #13
Posted 05 December 2012 - 09:15 AM
Don't understand what you need:

Do you want something that works like a remote switch
or
Do you want something, were you can write "10" and it will give you 10 items (a.k.a give 10 redpulses to an engine)?

I'm interested in helping you either way, just need to know what you want.
plazter #14
Posted 05 December 2012 - 09:38 AM
i got following setup so far DaWooShit;
10 barrels (more or less)
that i store all my items.
now what i want is:
Being able to tell my computer upstairs of the storage room that i want an specefic item, i tell it and it will send a message to that computer at the engine to start emitting a red stone signal :)/>
Lyqyd #15
Posted 05 December 2012 - 09:41 AM
You can't use numbers as variable names.
OmegaVest #16
Posted 05 December 2012 - 09:42 AM
What do you mean, it's not able to start? Also, a variable name cannot be just a number. It can be a number and something else, like fo2l, I think, but it cannot just be 23. Try using letters, or a table with numbers as the index.

But using numbers like that makes it so the computer cannot do math.


EDIT: BLAST! Ninja'd again.
Railalis #17
Posted 05 December 2012 - 09:58 AM
I just finished something that I think is similar to this.

http://www.computercraft.info/forums2/index.php?/topic/6713-inventorysorting-program/

Maybe it can be some help to your system? If you end up using mine, leave credit please :P/>
plazter #18
Posted 05 December 2012 - 10:52 AM
i figured a program for noobs thanks to all your codes :D/> Thanks alot guys ^^

ID = "25" -- Control computer upstairs my storage
while true do
rednet.open("top")
ID, status = rednet.receive()

if status == 'on' then
rs.setOutput("back", true)
sleep(25)
rs.setOutput("back", false)
end
end

That was the code i figured :P/>


EDIT:
- this way i can give the code to all the computers easyly by pastebin :P/>
http://pastebin.com/THVtcCEW
the code for pastebin ;)/>
OmegaVest #19
Posted 05 December 2012 - 10:56 AM
One thing before you go. . . .

You instantiate ID as a number, then immediately open it up to another number. You could just leave out the instantiation, and have the receive fill it.
plazter #20
Posted 05 December 2012 - 12:15 PM
One thing before you go. . . .

You instantiate ID as a number, then immediately open it up to another number. You could just leave out the instantiation, and have the receive fill it.
i didnt understand a shit of that man :P/>
plazter #21
Posted 05 December 2012 - 12:17 PM
I just finished something that I think is similar to this.

http://www.computerc...orting-program/

Maybe it can be some help to your system? If you end up using mine, leave credit please :P/>

The server im playing on aint having Red Power sorry man ^^
ChaddJackson12 #22
Posted 05 December 2012 - 02:35 PM
I could write you a program to do that, but not tonight, it would be a bit bigger than the other one I wrote for you…