Jump to content




Rednet Event, this is how you use it?


  • You cannot reply to this topic
10 replies to this topic

#1 kennyist

  • New Members
  • 9 posts

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?

#2 OmegaVest

  • Members
  • 436 posts

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")


#3 kennyist

  • New Members
  • 9 posts

Posted 12 December 2012 - 05:54 AM

View PostOmegaVest, on 12 December 2012 - 05:50 AM, said:

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




#4 Tiin57

    Java Lunatic

  • Members
  • 1,412 posts
  • LocationIndiana, United States

Posted 12 December 2012 - 05:56 AM

Nope. rednet.receive() returns three args:
id, msg, dist = rednet.receive()


#5 OmegaVest

  • Members
  • 436 posts

Posted 12 December 2012 - 06:02 AM

View Posttiin57, on 12 December 2012 - 05:56 AM, said:

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.

#6 kennyist

  • New Members
  • 9 posts

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


#7 ikkeniet

  • Members
  • 78 posts
  • Locationyou wil never know :P

Posted 12 December 2012 - 06:22 AM

View Postkennyist, on 12 December 2012 - 06:04 AM, said:

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

#8 kennyist

  • New Members
  • 9 posts

Posted 12 December 2012 - 06:24 AM

View Postikkeniet, on 12 December 2012 - 06:22 AM, said:

View Postkennyist, on 12 December 2012 - 06:04 AM, said:

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 :/

View Postkennyist, on 12 December 2012 - 06:04 AM, said:


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


#9 ikkeniet

  • Members
  • 78 posts
  • Locationyou wil never know :P

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 ""

#10 OmegaVest

  • Members
  • 436 posts

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.

#11 kennyist

  • New Members
  • 9 posts

Posted 12 December 2012 - 06:58 AM

View Postikkeniet, on 12 December 2012 - 06:35 AM, said:

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.

View PostOmegaVest, on 12 December 2012 - 06:41 AM, said:

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users