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

why doesn't this work

Started by xondk, 19 July 2012 - 05:34 PM
xondk #1
Posted 19 July 2012 - 07:34 PM
So I've begun playing around with skynet and wireless modems and such in general, it worked fine, but all of a sudden, the repeater function stopped working, and without it I cant sent up repeaters to send the message to the IRC server, I am running with the stock code as it is, but the repeater simply refuses to send the message onwards. any ideas?

This is the code for a simple, should work sender and receiver, the first time I used this code it worked, but once the turtle gets out of range and places a computer, and I set that computer to running the same response program the turtle refuses to work more then once.

This is the code


-- sender/repeater
local id, msg, dist
rednet.open("top")
while true do
    event, id, message = os.pullEvent()
  if event == "rednet_message"
  then
   print("received from "..id)
   rednet.send(id,"Received")
  end  
end

this is the turtle's program.

rednet.open("right")
local id, msg, dist
while not turtle.detectDown() do
   turtle.down()
end
while true do
  id = nil
  msg = nil
  dist = nil
  turtle.forward()
  rednet.broadcast("ping!")
  id, msg, dist = rednet.receive(2)
  sleep(1)
  if msg == nil then
   print("out of range")
   turtle.back()
   turtle.up()
   turtle.select(1)
   turtle.placeDown()
   turtle.up()
   turtle.select(2)
   turtle.placeDown()
   turtle.forward()
   break
  else
   print(dist.." blocks away from "..id)
  end
end

The idea is that I want a computer that simply sends a reply when receiving a rednet broadcast or send
and I want the turtle to walk away from that computer, then when its out of range place a new computer, which then can be set up as a new sender/repeater
and then rinse repeat, same process once the new computer is running the sender/repeater program, but for some reason it messes up and there is only one 'received' on the new computer
KaoS #2
Posted 19 July 2012 - 07:42 PM
It's degenerating man, it gets too far from the player and then minecraft doesn't load it, if mc loaded everything your pc would fry
OmegaVest #3
Posted 19 July 2012 - 07:45 PM
Walk back two spaces instead of one. I think- THINK -that the wireless signal requires modem-to-modem distance, and it DOES include up-down spaces. So, 64 actual blocks in a near-sphere shape. And, yeah, unless you are using chunkloaders (which I don't know will actually work with the terminals, about 20 chunks away, the signal stops.
KaoS #4
Posted 19 July 2012 - 07:51 PM
as well as that: you have no received variable being set
KaoS #5
Posted 19 July 2012 - 07:52 PM
AND MOST IMPORTANTLY, the computer does not automatically start up, use the peripheral api to make the turtle start the computer up
xondk #6
Posted 19 July 2012 - 08:04 PM
Even if I'm following the turtle, it will stop working, let me try to illustrate it
Sender = S , Turtle = T


               range
        S ---------------->T                       works

 
        S-----------------S---T                  Does not work


Even though the second computer is set up with exactly the same program it doesn't work, the turtle thinks its out of range, even though it is only out of the first senders range, the second sender should make the turtle work?
OmegaVest #7
Posted 19 July 2012 - 08:14 PM
Mmm. Only other thing I can think of is maybe the message is received while the turtle is in motion, and therefore, does not actually receive it. I don't know. Might, though, take a look at the parallel api. Have the listener run in the second thread.
MysticT #8
Posted 19 July 2012 - 08:17 PM
And how did you put the program in the computers the turtle place? Unless it's on the rom startup (wich affects every computer), it won't have the startup file with the code you need. And, as KaoS said, the computer won't turn on automatically, you need to turn it on (you can use the peripheral api for that).
xondk #9
Posted 19 July 2012 - 08:35 PM
I'm currently not relying on the repeat/sender code starting automaticly, rather i'm just starting it manually and the problem persists, the second computer won't act as a sender for more then 1 send.
KaoS #10
Posted 19 July 2012 - 08:50 PM
OMG, apologies for my stupid blindness, you need to enclose your code with a loop so it keeps executing or it will go through it once and then finish so try:


while true do
local id, msg, dist
rednet.open("top")
while true do
    event, id, message = os.pullEvent()
  if event == "rednet_message"
  then
   print("received from "..id)
   rednet.send(id,"Received")
  end 
end
end

lmfao, can't believe I never noticed :P/>/>
xondk #11
Posted 19 July 2012 - 09:11 PM
doesn't work, the second computer still doesn't do anything :P/>/>
MysticT #12
Posted 19 July 2012 - 09:12 PM
OMG, apologies for my stupid blindness, you need to enclose your code with a loop so it keeps executing or it will go through it once and then finish so try:


while true do
local id, msg, dist
rednet.open("top")
while true do
	event, id, message = os.pullEvent()
  if event == "rednet_message"
  then
   print("received from "..id)
   rednet.send(id,"Received")
  end
end
end

lmfao, can't believe I never noticed :P/>/>
It already has a loop, so you don't need to add another one.
KaoS #13
Posted 19 July 2012 - 09:16 PM
oh yeah, you're right, that seems fine, you just need to make sure that the main computer that you started with is still broadcasting hey
xondk #14
Posted 19 July 2012 - 09:17 PM
I suppose the question is, how would you guys code it?

to make the turtle go and place a computer with a modem when it reaches the edge of the wireless networks range?
KaoS #15
Posted 19 July 2012 - 09:19 PM
I've done it, unfortunately I don't have the code with me, give me a minute
KaoS #16
Posted 19 July 2012 - 09:26 PM
This is a basic draft of what I would do, untested as I am at work, give it a try


term.clear()
term.setCursorPos(1,1)
rednet.open("top")
rednet.open("bottom")
rednet.open("front")
rednet.open("back")
rednet.open("left")
rednet.open("right")
while true do
local msg=nil
local id,msg,dist=rednet.receive()
if msg then
  print("ID: "..id.."nMESSAGE: "..msg.."nDISTANCE: "..dist)
  rednet.broadcast(msg)
end
end
KaoS #17
Posted 19 July 2012 - 09:32 PM
then the turtle code:


rednet.open("right")
while true do
local msg=nil
local id,msg,dist=rednet.receive(2)
if not msg then break end
end
turtle.back()
turtle.back()
turtle.up()
turtle.select(1)
turtle.placeDown()
turtle.up()
turtle.select(2)
turtle.placeDown()
turtle.forward()
turtle.down()
turtle.down()
peripheral.call("back","turnOn")

That will only place one pc, it's quite messy as it is a rough draft, enclose it in a loop if you want it to keep placing computers
KaoS #18
Posted 19 July 2012 - 09:34 PM
so what you do is you place a computer and set it to keep pulsing a rednet message every second, place the turtle and give it the supplies, start it up and enjoy
MysticT #19
Posted 19 July 2012 - 09:36 PM
This is a basic draft of what I would do, untested as I am at work, give it a try


term.clear()
term.setCursorPos(1,1)
rednet.open("top")
rednet.open("bottom")
rednet.open("front")
rednet.open("back")
rednet.open("left")
rednet.open("right")
while true do
local msg=nil
local id,msg,dist=rednet.receive()
if msg then
  print("ID: "..id.."nMESSAGE: "..msg.."nDISTANCE: "..dist)
  rednet.broadcast(msg)
end
end
You should use send instead of broadcast, or 2 computers in range will spam rednet (one broadcasts, the other one receives and broadcasts, the first one receives that and broadcasts again, etc.).

then the turtle code:


rednet.open("right")
while true do
local msg=nil
local id,msg,dist=rednet.receive(2)
if not msg then break end
end
turtle.back()
turtle.back()
turtle.up()
turtle.select(1)
turtle.placeDown()
turtle.up()
turtle.select(2)
turtle.placeDown()
turtle.forward()
turtle.down()
turtle.down()
peripheral.call("back","turnOn")

That will only place one pc, it's quite messy as it is a rough draft, enclose it in a loop if you want it to keep placing computers
rednet.receive() won't return if there's no message, so the first loop will never end.
KaoS #20
Posted 19 July 2012 - 09:38 PM
you can then set the pc to listen for input and pulse it out like the normal code I gave you above and set the turtle to ping again, adapt it as you wish, on my server I like to set things to pulse a message twice a second to disrupt enemy communications (I have gone to the point where I broadcast 100 times a second but lag was an issue) and I can use it as a range tester as well to set up broadcasting satellites
KaoS #21
Posted 19 July 2012 - 09:39 PM
This is a basic draft of what I would do, untested as I am at work, give it a try


term.clear()
term.setCursorPos(1,1)
rednet.open("top")
rednet.open("bottom")
rednet.open("front")
rednet.open("back")
rednet.open("left")
rednet.open("right")
while true do
local msg=nil
local id,msg,dist=rednet.receive()
if msg then
  print("ID: "..id.."nMESSAGE: "..msg.."nDISTANCE: "..dist)
  rednet.broadcast(msg)
end
end
You should use send instead of broadcast, or 2 computers in range will spam rednet (one broadcasts, the other one receives and broadcasts, the first one receives that and broadcasts again, etc.).

then the turtle code:


rednet.open("right")
while true do
local msg=nil
local id,msg,dist=rednet.receive(2)
if not msg then break end
end
turtle.back()
turtle.back()
turtle.up()
turtle.select(1)
turtle.placeDown()
turtle.up()
turtle.select(2)
turtle.placeDown()
turtle.forward()
turtle.down()
turtle.down()
peripheral.call("back","turnOn")

That will only place one pc, it's quite messy as it is a rough draft, enclose it in a loop if you want it to keep placing computers
rednet.receive() won't return if there's no message, so the first loop will never end.

that's why the rednet.receive(2) times out after 2 seconds, msg then does not get a value so the if statement breaks the loop
KaoS #22
Posted 19 July 2012 - 09:43 PM
you're right, but what is the point of these computers being placed then? they just send back whatever they receive, you should put in a system to filter out what you sent or something, a table that is included in the message and is a list of all the computers that have passed on the message, when a transmitting station gets it then it checks the table. if it is not in the table then it adds itself, if it is then it cancels, I used a system like this on another program but in all honesty I did not see that when I first made my system for this, thanks
xondk #23
Posted 20 July 2012 - 01:24 AM
the point is to get a turtle to do the measuring and such requirements rather then going by coordinates and such, for setting up a lot of repeaters to transfer wireless over long distances without changing the config
KaoS #24
Posted 20 July 2012 - 02:38 PM
yes but then the program you are loading on them only sends back what it receives, it does not relay it onwards
KaoS #25
Posted 20 July 2012 - 02:39 PM
ok tell you what dude, do you have mxit? I would suggest fb but it's blocked at work, make a mxit account and pm me the id