11 posts
Location
~/Desktop
Posted 30 January 2013 - 07:11 AM
Title: Rednet listening system not working as intended.
Hello! I'm new to Computercraft and LUA so I have some questions that shouldn't be so hard to answer for you guys. I've been working on a project for a spleefing arena where a turtle will function as a repair bot. My code can be found here:
http://pastebin.com/qvF864pv, my problem that I've encountered is that when I run the program the turtle returns the value "15" and then you go back into the terminal. How do I fix it and what is the problem with the code? My instinct tells me that I've done something wrong in the listen() function that is supposed to listen for incoming rednet signals…
Thanks in advance!
Orginalet
P.S I'm running the 1.3 version of Computercraft.
537 posts
Location
Copenhagen, Denmark
Posted 30 January 2013 - 08:15 AM
You are probably receiving a rednet message from a computer with the ID #15.
11 posts
Location
~/Desktop
Posted 30 January 2013 - 08:56 AM
Thank you for the fast answer! Is there a way to work around this, like blocking a signal from that particular ID number?
1522 posts
Location
The Netherlands
Posted 30 January 2013 - 09:14 AM
You could select wich ID's you want to receive.
local p1, p2 = rednet.receive()
if p1 == yourChoiceOfID and p2 == "CertainMessage" then
print("Execute code")
elseif etc.
end
11 posts
Location
~/Desktop
Posted 30 January 2013 - 09:33 AM
You could select wich ID's you want to receive.
local p1, p2 = rednet.receive()
if p1 == yourChoiceOfID and p2 == "CertainMessage" then
print("Execute code")
elseif etc.
end
That's cool, I tried to edit my code into
function listen()
while true do
local id, mess = rednet.receive()
if id == "2270" and mess == "go" then
print("Command GO received.")
os.sleep(1)
start()
else print("Command not recognized. Or wrong ID")
end
end
but the turtle still returns the value 15… Did I implement it completely wrong?
Edit: When I break the turtle and then place it again the value varies from 15,16 and 17… Could it be anything else than other computers interfering?
497 posts
Location
The Big Apple, NY
Posted 30 January 2013 - 10:15 AM
I quickly looked over ur code…there is no print that references a variable only set strings…are u sure u properly updated the code on the turtle…
11 posts
Location
~/Desktop
Posted 30 January 2013 - 10:21 AM
100% sure. I tried breaking the turtle and then download the new code directly from my
pastebin.
436 posts
Posted 30 January 2013 - 10:23 AM
Ah, well I don't know this is the problem, but after following the program, and assuming it got the correct command, you run into an infinite loop problem with move/place. Move calls place, which calls move if it cannot place. I would think about re-writing that section of code. Maybe just let place return to move once it completes.
11 posts
Location
~/Desktop
Posted 30 January 2013 - 10:27 AM
Ah, well I don't know this is the problem, but after following the program, and assuming it got the correct command, you run into an infinite loop problem with move/place. Move calls place, which calls move if it cannot place. I would think about re-writing that section of code. Maybe just let place return to move once it completes.
I'll look into that once I get the rednet sorted. Thank you for spotting that! :)/>
2005 posts
Posted 30 January 2013 - 11:09 AM
Does this code even run? You seem to not have properly closed all your functions.
497 posts
Location
The Big Apple, NY
Posted 30 January 2013 - 11:18 AM
I'm amazed you can even get the program running….i'm having lots of errors and a un closed loop…
just tested your rednet function by itself and it works fine….
436 posts
Posted 30 January 2013 - 12:02 PM
Okay next query (given the above few posts): Is there a reason you cannot update to the current ComputerCraft version? Or is it a matter of preference?
2088 posts
Location
South Africa
Posted 30 January 2013 - 05:54 PM
That's cool, I tried to edit my code into
if id == "2270" and mess == "go" then
but the turtle still returns the value 15… Did I implement it completely wrong?
Edit: When I break the turtle and then place it again the value varies from 15,16 and 17… Could it be anything else than other computers interfering?
ID is a number. rednet.receive() returns the ID as a number, not a string.
11 posts
Location
~/Desktop
Posted 31 January 2013 - 05:07 AM
I fixed it and the program runs properly now. You were right, I forgot to close 2 for loops and I had missed the "for i = x, y" and just used "for x, y". I have never worked with for loops before but it makes sense now that I know what I did wrong. If you want to take a look at the fixed but still unfinished code it's the same
link as before.
Thank you for your help and input! :)/>
Edit: Oh and btw, I cannot update my Computercraft version since I'm playing on a tekkit server with version 1.3.