Posted 16 March 2015 - 07:57 PM
I am fixing up some code that someone made. I get the error
and here is the code for the main program
window:57: Expected Number
whenever I try to call the function rednetControl() here is the code for the function
function rednetControl()
term.setCursorPos(1, 1);
term.setBackgroundColor(colors.lightBlue);
term.setTextColor(colors.white);
for i = 1, 20 do
for j = 1, 26 do
if (i == 1 or i == 20 or j == 1 or j == 26) then
term.setBackgroundColor(colors.blue);
end
write(" ");
term.setBackgroundColor(colors.lightBlue);
end
if (i ~= 20) then
print(" ");
end
end
term.setCursorPos(4, 3);
write("Advanced Rednet Console");
term.setBackgroundColor(colors.orange);
term.setCursorPos(3, 6);
text.centerPrint("OPEN Rednet");
term.setCursorPos(3, 8);
text.centerPrint("CLOSE Rednet");
term.setCursorPos(3, 10);
text.centerPrint("Rednet Broadcast");
term.setCursorPos(3, 12);
text.centerPrint("Send Message");
term.setCursorPos(3, 14);
text.centerPrint("Get Message");
term.setCursorPos(3, 16);
text.centerPrint("Computer ID");
term.setCursorPos(3, 18);
text.centerPrint("Exit");
local event, button, x, y = os.pullEvent("mouse_click");
if (button == 1) then
if (y == 6) then
rednet.open("back");
showInformationMessage("Rednet Turned On");
sleep(2);
end
if (y == 8) then
rednet.close("back");
showInformationMessage("Rednet Turned Off");
sleep(2);
end
if (y == 10) then
message = showInputDialog("Broadcast Message");
showInformationMessage("Broadcasting...", "");
rednet.broadcast(message);
sleep(2);
end
if (y == 12) then
id = tonumber(showInputDialog("Target ID"));
message = showInputDialog("Enter Message");
showInformationMessage("Sending Message...", "");
rednet.send(id, message);
sleep(2);
end
if (y == 14) then
timeout = tonumber(showInputDialog("Enter Timeout"));
showInformationMessage("Waiting for", "message");
id, msg = rednet.receive(timeout);
if (msg == nil) then
showErrorMessage("Receive Timeout.");
sleep(2);
else
showInformationMessage(id, msg);
sleep(5);
end
end
if (y == 16) then
showInformationMessage("Computer ID", os.getComputerID());
sleep(5);
end
if (y == 18) then
return;
end
rednetControl();
end
end
and here is the code for the main program
os.loadAPI("APIS/text")
os.loadAPI("APIS/boot")
os.loadAPI("APIS/gameutils")
os.loadAPI("APIS/menu")
rednet.open("back");
local connected = 0;
local serverName = nil;
local serverID = 0;
function repaint()
term.setCursorPos(1, 1);
term.setBackgroundColor(colors.white);
for i = 1, 20 do
for j = 1, 26 do
write(" ");
end
print();
end
if (connected == 0) then
term.setBackgroundColor(colors.red);
else
term.setBackgroundColor(colors.green);
end
term.setTextColor(colors.white);
term.setCursorPos(1, 1);
write(" ");
term.setCursorPos(1, 20);
write(" ");
term.setCursorPos(1, 1);
write(serverName);
end
function connectToServer()
rednet.broadcast("$INFO");
id, msg = rednet.receive(5);
if (msg == nil) then
showErrorMessage("No Carrier");
sleep(3);
os.reboot();
else
serverName = msg;
serverID = id;
connected = 1;
end
end
function showErrorMessage(message)
term.setBackgroundColor(colors.red);
term.setTextColor(colors.white);
for i = 8, 13 do
term.setCursorPos(2, i);
for j = 1, 24 do
write(" ");
end
print();
end
term.setCursorPos(11, 9);
write("Error");
term.setCursorPos(4, 11);
write(message);
end
function showInformationMessage(line1, line2)
term.setBackgroundColor(colors.lightBlue);
term.setTextColor(colors.white);
for i = 8, 13 do
term.setCursorPos(2, i);
for j = 1, 24 do
write(" ");
end
print();
end
term.setCursorPos(11, 9);
write("Message");
term.setCursorPos(4, 11);
write(line1);
term.setCursorPos(4, 12);
write(line2);
end
function showOSInformation()
term.setBackgroundColor(colors.white);
term.setTextColor(colors.lightGray);
term.setCursorPos(4, 5);
text.centerPrint("PDATerm v0.1");
term.setCursorPos(4, 7);
text.centerPrint("A Free Mobile Terminal");
term.setCursorPos(4, 8);
text.centerPrint("for ComputerCraft");
end
function lock()
term.setCursorPos(1, 1);
term.setBackgroundColor(colors.black);
term.setTextColor(colors.white);
for i = 1, 20 do
for j = 1, 26 do
if (i == 1 or i == 20 or j == 1 or j == 26) then
term.setBackgroundColor(colors.red);
end
write(" ");
term.setBackgroundColor(colors.black);
end
if (i ~= 20) then
print();
end
end
term.setCursorPos(5, 3);
text.centerPrint("--Enter Passcode--");
cpass = "1234";
pass = "";
term.setTextColor(colors.white);
while(pass ~= cpass) do
pass = "";
term.setCursorPos(5, 15);
write(" - - - - ");
for i = 1, 4 do
term.setCursorPos(5 + i * 3, 15);
local event, key = os.pullEvent("char");
pass = pass .. key;
write("*");
end
end
end
function showInputDialog(message)
term.setBackgroundColor(colors.lightBlue);
term.setTextColor(colors.brown);
for i = 4, 17 do
for j = 1, 24 do
write(" ");
end
end
term.setCursorPos(4, 6);
write(message);
term.setCursorPos(5, 14);
input = read();
return input;
end
function rednetControl()
term.setCursorPos(1, 1);
term.setBackgroundColor(colors.lightBlue);
term.setTextColor(colors.white);
for i = 1, 20 do
for j = 1, 26 do
if (i == 1 or i == 20 or j == 1 or j == 26) then
term.setBackgroundColor(colors.blue);
end
write(" ");
term.setBackgroundColor(colors.lightBlue);
end
if (i ~= 20) then
print(" ");
end
end
term.setCursorPos(4, 3);
write("Advanced Rednet Console");
term.setBackgroundColor(colors.orange);
term.setCursorPos(3, 6);
text.centerPrint("OPEN Rednet");
term.setCursorPos(3, 8);
text.centerPrint("CLOSE Rednet");
term.setCursorPos(3, 10);
text.centerPrint("Rednet Broadcast");
term.setCursorPos(3, 12);
text.centerPrint("Send Message");
term.setCursorPos(3, 14);
text.centerPrint("Get Message");
term.setCursorPos(3, 16);
text.centerPrint("Computer ID");
term.setCursorPos(3, 18);
text.centerPrint("Exit");
local event, button, x, y = os.pullEvent("mouse_click");
if (button == 1) then
if (y == 6) then
rednet.open("back");
showInformationMessage("Rednet Turned On");
sleep(2);
end
if (y == 8) then
rednet.close("back");
showInformationMessage("Rednet Turned Off");
sleep(2);
end
if (y == 10) then
message = showInputDialog("Broadcast Message");
showInformationMessage("Broadcasting...", "");
rednet.broadcast(message);
sleep(2);
end
if (y == 12) then
id = tonumber(showInputDialog("Target ID"));
message = showInputDialog("Enter Message");
showInformationMessage("Sending Message...", "");
rednet.send(id, message);
sleep(2);
end
if (y == 14) then
timeout = tonumber(showInputDialog("Enter Timeout"));
showInformationMessage("Waiting for", "message");
id, msg = rednet.receive(timeout);
if (msg == nil) then
showErrorMessage("Receive Timeout.");
sleep(2);
else
showInformationMessage(id, msg);
sleep(5);
end
end
if (y == 16) then
showInformationMessage("Computer ID", os.getComputerID());
sleep(5);
end
if (y == 18) then
return;
end
rednetControl();
end
end
function displayMainMenu()
term.setBackgroundColor(colors.yellow);
term.setTextColor(colors.red);
term.setCursorPos(3, 5);
text.centerPrint("Current GPS Position");
term.setCursorPos(3, 7);
text.centerPrint("Mail System");
term.setCursorPos(3, 9);
text.centerPrint("Enter Chat");
term.setCursorPos(3, 11);
text.centerPrint("Rednet Console");
term.setCursorPos(3, 13);
text.centerPrint("Reconnect");
term.setCursorPos(3, 15);
text.centerPrint("Redbook");
term.setCursorPos(3,17)
text.centerPrint("Shutdown")
local event, button, x, y = os.pullEvent("mouse_click");
if (button == 1) then
if (y == 5) then
showInformationMessage("Getting Location", "");
if (gps.locate(5) == nil) then
showErrorMessage("No GPS Signal.");
sleep(2);
else
x, y, z = gps.locate();
showInformationMessage("Your Location: ", x .. ", " .. y .. ", " .. z);
sleep(5);
end
end
if (y == 7) then
end
if (y == 9) then
end
if (y == 11) then
showInformationMessage("Please Wait...", "");
sleep(2);
rednetControl();
end
if (y == 13) then
showInformationMessage("Connecting...", "");
connected = 0;
connectToServer();
end
if (y == 15) then
shell.run("redbook/start")
end
if (y == 17) then
showInformationMessage("Shutting Down...", "");
sleep(2);
os.shutdown();
end
end
repaint();
displayMainMenu();
end
lock();
connectToServer();
repaint();
showOSInformation();
if (connected == 0) then
showErrorMessage("No Carrier");
sleep(5);
os.reboot();
else
showInformationMessage("Connected to", serverName);
sleep(3);
end
repaint();
displayMainMenu();