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

Problems with rednet

Started by Sippycup, 01 December 2012 - 11:26 AM
Sippycup #1
Posted 01 December 2012 - 12:26 PM
Hello everyone. This is my first attempt at creating a multi turtle quarry clearing system. For some reason the program on my computer will end after entering a Bot number. FYI the turtles rednet is already open and getJob() function has been ran. Thanks in advance!


I want it to:

1. pass the bot number choice into the callBot() function from the event pull

2. have the "Enter Job" text appear and ask for job number

3. send the x,y,zed coordinates to the respective turtle

Computer code program "Manage"

[php]choice = 0
botNum = 0

function clear()
term.clear()
term.setCursorPos(1,1)
end

function callBot(choice)
if choice == 1 then
rednet.send(21,"yes")
term.setCursorPos(1,1)
print("Enter Job #")
local jobNum1 = 1
local input = read("*")
if input == jobNum1 then
print("Sending Bot #"..choice.." to Job #"..input)
rednet.send(21,-9)
rednet.send(21,-122)
rednet.send(21,62)
else
print("Invalid Job #")
mainmenu()
end
end
end

function mainmenu()
print("Enter Bot# (1-2) ")
event,botNum = os.pullEvent("char")
if botNum == "1" then
clear()
sleep(1)
choice = botNum
term.setCursorPos(1,1)
callBot(choice)
else
clear()
sleep(1)
print("Bot out of order")
mainmenu()
end
end

mainmenu()[/php]


Turtle function that checks for job number:

[php]function getJob()
while jobAvailable do
id,message = rednet.receive()

if message == "yes" then
id,qx = rednet.receive()
id,qz = rednet.receive()
id,qy = rednet.receive()

digQuarry(qx,qz,qy)

elseif message == "no" then
jobAvailable = false
end
end
end

getJob()[/php]
Cranium #2
Posted 01 December 2012 - 01:27 PM

if choice == 1 then
--needs to be
if choice == "1" then
Since read() returns strings only, as well as os.pullEvent("char") returns string characters.

Edit: Try following your variables through your code. If a variable suddenly changes down the line, make sure it's fixed. You can do some debugging with menu systems by using print(variable) commands. It really helps you find where your error is.
Edited on 01 December 2012 - 12:31 PM
Sippycup #3
Posted 01 December 2012 - 04:16 PM
Thank you Ninja :)/> . Still getting used to lua.