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

Rednet Event, this is how you use it?

Started by kennyist, 12 December 2012 - 04:19 AM
kennyist #1
Posted 12 December 2012 - 05:19 AM
Hi,

Just wondering if this is the right way to use the rednet event:

  rednet_message, id , msg, dist = os.pullEvent()
  print(id, msg, dist)

If so im getting problems with this…

Or how do you use it?
OmegaVest #2
Posted 12 December 2012 - 05:50 AM
More or less, that should work. What kind of problems are you having with it?

Unless you are only trying to pull rednet_message, in which case you should do this:


emty, is, msg, dist = os.pullEvent("rednet_message")
kennyist #3
Posted 12 December 2012 - 05:54 AM
More or less, that should work. What kind of problems are you having with it?

Unless you are only trying to pull rednet_message, in which case you should do this:


emty, is, msg, dist = os.pullEvent("rednet_message")

Doesnt seem to work either (Better then what happened before though). I'm trying to use it in this:


function drawLines()
  term.clear()
  term.setCursorPos(1,1)
  paintutils.drawLine(1, 10, 50, 10, 128)
end

rednet.open("right")
red1 = paintutils.loadImage(red)
green1 = paintutils.loadImage(green)

while true do
  emty, id, msg, dist = os.pullEvent("rednet_message")
  print(id, msg, dist)
	if id == 3 then
	  if msg == "green" then
		drawLines()
		paintutils.drawImage(green1, 25, 10)
	  else
		drawLines()
		paintutils.drawImage(red1, 25, 10)
	  end
	else
	drawLines()
	end
end


Tiin57 #4
Posted 12 December 2012 - 05:56 AM
Nope. rednet.receive() returns three args:

id, msg, dist = rednet.receive()
OmegaVest #5
Posted 12 December 2012 - 06:02 AM
Nope. rednet.receive() returns three args:

id, msg, dist = rednet.receive()

…Except he's using os.pullEvent, which in the case of rednet_message, returns 4 args, event, id, message and distance travelled.

And, again, you don't ever say what happens, kennyist. You say that it isn't working, but unless we know what it IS doing, we can't necessarily know how to help you.
kennyist #6
Posted 12 December 2012 - 06:04 AM
With this:


function drawLines()
  term.clear()
  term.setCursorPos(1,1)
  paintutils.drawLine(1, 10, 50, 10, 128)
end
rednet.open("right")
red1 = paintutils.loadImage(red)
green1 = paintutils.loadImage(green)
while true do
  emty, id, msg, dist = os.pullEvent("rednet_message")
  print(id, msg, dist)

	if id == "3" then
	  if msg == "green" then
		drawLines()
		paintutils.drawImage(green1, 25, 10)
	  else
		drawLines()
		paintutils.drawImage(red1, 25, 10)
	  end
	else
drawLines()
end
end

At the moment im geting "paintutils:14: Expected string"

adding quotation marks onto the loadimage paramaters stops this, but then nothing shows up atall.

Yeah, the pull event is not working, this doesnt even show anything.


function drawLines()
  term.clear()
  term.setCursorPos(1,1)
  paintutils.drawLine(1, 10, 50, 10, 128)
end
rednet.open("right")
red1 = paintutils.loadImage("red")
green1 = paintutils.loadImage("green")
while true do
  emty, id, msg, dist = os.pullEvent("rednet_message")
  print(id, msg, dist)
end
ikkeniet #7
Posted 12 December 2012 - 06:22 AM
With this:


function drawLines()
  term.clear()
  term.setCursorPos(1,1)
  paintutils.drawLine(1, 10, 50, 10, 128)
end
rednet.open("right")
red1 = paintutils.loadImage(red)
green1 = paintutils.loadImage(green)
while true do
  emty, id, msg, dist = os.pullEvent("rednet_message")
  print(id, msg, dist)

	if id == "3" then
	  if msg == "green" then
		drawLines()
		paintutils.drawImage(green1, 25, 10)
	  else
		drawLines()
		paintutils.drawImage(red1, 25, 10)
	  end
	else
drawLines()
end
end

At the moment im geting "paintutils:14: Expected string"

adding quotation marks onto the loadimage paramaters stops this, but then nothing shows up atall.

I c the problem you have to use red1 = paintutils.loadImage("red") with "" for a name
kennyist #8
Posted 12 December 2012 - 06:24 AM
With this:


function drawLines()
  term.clear()
  term.setCursorPos(1,1)
  paintutils.drawLine(1, 10, 50, 10, 128)
end
rednet.open("right")
red1 = paintutils.loadImage(red)
green1 = paintutils.loadImage(green)
while true do
  emty, id, msg, dist = os.pullEvent("rednet_message")
  print(id, msg, dist)

	if id == "3" then
	  if msg == "green" then
		drawLines()
		paintutils.drawImage(green1, 25, 10)
	  else
		drawLines()
		paintutils.drawImage(red1, 25, 10)
	  end
	else
drawLines()
end
end

At the moment im geting "paintutils:14: Expected string"

adding quotation marks onto the loadimage paramaters stops this, but then nothing shows up atall.

I c the problem you have to use red1 = paintutils.loadImage("red") with "" for a name

Alrady fixed that and said then nothing shows up after i do that. The event doesnt work still :/

adding quotation marks onto the loadimage paramaters stops this, but then nothing shows up atall.

Yeah, the pull event is not working, this doesnt even show anything.


function drawLines()
  term.clear()
  term.setCursorPos(1,1)
  paintutils.drawLine(1, 10, 50, 10, 128)
end
rednet.open("right")
red1 = paintutils.loadImage("red")
green1 = paintutils.loadImage("green")
while true do
  emty, id, msg, dist = os.pullEvent("rednet_message")
  print(id, msg, dist)
end
ikkeniet #9
Posted 12 December 2012 - 06:35 AM
try this


function drawLines()
  term.clear()
  term.setCursorPos(1,1)
  paintutils.drawLine(1, 10, 50, 10, 128)
end
rednet.open("right")
red1 = paintutils.loadImage("red")
green1 = paintutils.loadImage("green")
while true do
  event, id, msg, dist = os.pullEvent("rednet_message")
  print(id, msg, dist)
  if id == 1 then
	if msg == "green" then
	  drawLines()
	  paintutils.drawImage(green1, 25, 10)
	elseif msg == "red" then
	  drawLines()
	  paintutils.drawImage(red1, 25, 10)
	end
  else
	sleep(10)
	drawLines()
  end
end

the id shut not be inbetween ""
OmegaVest #10
Posted 12 December 2012 - 06:41 AM
Before we go too far, where are the "red" and "green" images stored on the computer? They require absolute paths, just like the fs api.
kennyist #11
Posted 12 December 2012 - 06:58 AM
try this


function drawLines()
  term.clear()
  term.setCursorPos(1,1)
  paintutils.drawLine(1, 10, 50, 10, 128)
end
rednet.open("right")
red1 = paintutils.loadImage("red")
green1 = paintutils.loadImage("green")
while true do
  event, id, msg, dist = os.pullEvent("rednet_message")
  print(id, msg, dist)
  if id == 1 then
	if msg == "green" then
	  drawLines()
	  paintutils.drawImage(green1, 25, 10)
	elseif msg == "red" then
	  drawLines()
	  paintutils.drawImage(red1, 25, 10)
	end
  else
	sleep(10)
	drawLines()
  end
end

the id shut not be inbetween ""

alrady tried that, same thing.

Before we go too far, where are the "red" and "green" images stored on the computer? They require absolute paths, just like the fs api.

saved with paint program in main dir.