Posted 22 May 2013 - 10:31 AM
I have been programming since i was seven years old (only 12 now), and had never done anything in lua. Because of my background i decided to "dive right in" so to speak. I programmed the start of what would be an OS. Very simple, but very complex as well. I made it check for directorys needed to run, and if missing it would create them. Then i could controll it at this time with comments, so that it would login, or create a new user every time it was run. right now i am working on the login function. but every time i try to login, it decides not to work, and i dont know why.
HERE is the error: winmc:94: attempt to index? (a nil value)
This doesnt make sense, where is the nil in "local uin = uir.readLine();"
this is my code:
Please help me with this, and thanks in advance.
HERE is the error: winmc:94: attempt to index? (a nil value)
This doesnt make sense, where is the nil in "local uin = uir.readLine();"
this is my code:
-- logo for windows MC
local w,h = term.getSize();
local col = term.setTextColor;
local bgc = term.setBackgroundColor;
--logo = {" __ __ __ "; IGNORE
-- "| | | |\ | | \ / \ | | / "; THIS
-- "| | | | | | | | | | | | | "; <
-- "| | | | \ | | | | | | | \_ ";
-- "| | | | | | | | | | | | | \ ";
-- "\__/ \__/ | | \| |__/ \__/ \/\/ __/ ";
-- " ";
-- " M C ";
-- }-- END LOGO
logo = {
"WINDOWS";
" M C ";
}
function checkOsReq()
term.setCursorPos(0,1);
--check for color suporting computer
if not term.isColor() then
error("CANNOT LOAD; MUST BE RAN ON AN ADVANCED COMPUTER");
end
--check for winMC directory
if not fs.isDir("/.winMC") then
col(colors.red);
print("FOLDER: /.winMC DOES NOT EXIST");
fs.makeDir("/.winMC");
col(colors.green);
print("CREATED FOLDER: /.winMC");
end
if not fs.isDir("/.winMC/.OS") then
col(colors.red);
print("FOLDER: /.winMC/.OS DOES NOT EXIST");
fs.makeDir("/.winMC/.OS");
col(colors.green);
print("CREATED FOLDER: /.winMC/.OS");
end
if not fs.isDir("/.winMC/.user") then
col(colors.red);
print("FOLDER: /.winMC/.user DOES NOT EXIST");
fs.makeDir("/.winMC/.user");
col(colors.green);
print("CREATED FOLDER: /.winMC/.user");
end
end
function createProfile()
local next = false;
local usrn;
local pass;
local hint;
col(colors.green);
term.setCursorPos(0,1);
screenClear();
print("PLEASE TYPE YOUR DESIRED USERNAME:");
usrn = read();
print("PLEASE TYPE YOUR DESIRED PASSWORD:");
pass = read("*");
print("PLEASE TYPE YOUR PASSWORD HINT:");
hint = read();
if not fs.isDir("/.winMC/.user/"..usrn) then
fs.makeDir("/.winMC/.user/"..usrn);
local usw = fs.open("/.winMC/.user/"..usrn.."/.userInfo","w");
usw.writeLine(usrn);
usw.writeLine(pass);
usw.writeLine(hint);
usw.close();
else
print("ERROR, USER ALREADY EXISTS, CHANGE USERNAME");
end
end
function login()
screenClear();
term.setCursorPos(0,1);
local usn;
local pass;
print("LOGIN");
print("USERNAME:");
term.setCursorPos(0,3);
print("PASSWORD:");
term.setCursorPos(10,2);
usn = read();
term.setCursorPos(10,3);
pass = read();
if fs.isDir("/.winMC/.user/"..usn) then
if fs.exists("/.winMC/.user/"..usn.."/.userInfo") then
uir = fs.open("/.winMC/.user"..usn.."/.userInfo","r");
local uin = uir.readLine();
if uin == usn then
uin = uir.readLine();
if uin == pass then
print("SUCESS");
else
print("NO, you SUCK AT LIFE!");
end
end
uir.close();
end
end
end
function screenClear()
term.clear();
bgc(colors.lightBlue);
for i=1,w do
for j=1,h do
term.setCursorPos(i,j);
write(" ");
end
end
end
function startScreen()
col(colors.green);
bgc(colors.lightBlue);
for i=1,#logo do
term.setCursorPos(w/2 - 3,i);
term.write(logo[i]);
term.setCursorPos(w/2 - 5,4);
term.write("LOADING ...");
end
sleep(3);
end
screenClear();
startScreen();
screenClear();
checkOsReq();
--sleep(2);
--createProfile();
login();
sleep(2);
Please help me with this, and thanks in advance.