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

[Rednet] Can't Seem to Figure This Out (solved)

Started by LikeableBump, 07 January 2013 - 04:39 AM
LikeableBump #1
Posted 07 January 2013 - 05:39 AM
I want to write a program that sends information about a redstone energy cell (from Thermal Expansion) using a computer connected with MiscPeripherals, to another computer, that then prints it onto a monitor. I have all the code written but it doesn't seem to work. I've been trying to figure it out for the past 2 hours but nothing I do seems to work… This is the first time I've tried to do anything with rednet so it's pretty confusing to me. Any help is greatly appreciated.

Here's the code for the sender:


rednet.open("right")
m = peripheral.wrap("left")
noEn = false
fullEn = false
while true do
  data = m.get()
  if (data["No Energy"]) and not noEn then
	redstone.setOutput("back", true)
	noEn = true
	rednet.broadcast("enOn")
  else
	noEn = false
  end

  if (data["Full Energy"]) and not fullEn then
	redstone.setOutput("back", false)
	fullEn = true
	rednet.broadcast("enOff")
  else
	fullEn = false
  end

  sleep(0.5)
end

Here is the code for the receiver:


rednet.open("right")
m = peripheral.wrap("left")

m.clear()
m.setCursorPos(9,1)
m.write("Engine Status")

m.setCursorPos(1,2) --Probably an inefficient way to do this but it works.
   m.write("#############################")
m.setCursorPos(1,3)
  m.write("#						   #")
m.setCursorPos(1,4)
  m.write("#						   #")
m.setCursorPos(1,5)
  m.write("#						   #")
m.setCursorPos(1,6)
  m.write("#						   #")
m.setCursorPos(1,7)
  m.write("#						   #")
m.setCursorPos(1,8)
  m.write("#						   #")
m.setCursorPos(1,9)
  m.write("#						   #")
m.setCursorPos(1,10)
  m.write("#						   #")
m.setCursorPos(1,11)
  m.write("#						   #")
m.setCursorPos(1,12)
  m.write("#############################")
while true do
  x = rednet.receive()
  if x == enOn then
	m.setCursorPos(6,9)
	m.write("Engines On")
  else
	m.setCursorPos(6,9)
	m.write("Engines Off")
  end
end
Lyqyd #2
Posted 07 January 2013 - 05:43 AM
rednet.receive() returns the ID of the sender and the message sent (as well as the distance to the sender, which isn't particularly relevant here). You are only catching the return value of the ID, then comparing that. You could try changing it to:

id, x = rednet.receive()

Also, you need to have enOn in quotes down at the bottom.
LikeableBump #3
Posted 07 January 2013 - 07:13 AM
Ahh thank you! Got that working :)/> I think I'll get the hang of this yet. Quick question though so I don't have to make a new thread; how do you set text color? I tried setTextColor("colors.blue") but it returns "Was expecting a number." I also tried the decimal and hexadecimal numbers on the color api wiki page, but it just returned the same error.

Nevermind I'm an idiot. I removed the quotation marks and it worked.