Posted 22 May 2013 - 11:41 PM
I am busy working away on my new OS, and I encountered annother problem, that i have NO IDEA how to solve. The error is "winMC:29: attempt to index ? (a nil value)" Where is the nil in file.write(contents); ?
BY THE WAY: the pastebinGet function was copied from suicidalstdz Ender OS, I GIVE FULL CREDIT TO HIM FOR MAKING THIS FUNCTION.
here is my code:
BY THE WAY: the pastebinGet function was copied from suicidalstdz Ender OS, I GIVE FULL CREDIT TO HIM FOR MAKING THIS FUNCTION.
here is my code:
-- logo for windows MC
local w,h = term.getSize();
local col = term.setTextColor;
local bgc = term.setBackgroundColor;
local user;
local userDir;
--logo = {" __ __ __ "; IGNORE
-- "| | | |\ | | \ / \ | | / "; THIS
-- "| | | | | | | | | | | | | "; <
-- "| | | | \ | | | | | | | \_ ";
-- "| | | | | | | | | | | | | \ ";
-- "\__/ \__/ | | \| |__/ \__/ \/\/ __/ ";
-- " ";
-- " M C ";
-- }-- END LOGO
logo = {
"WINDOWS";
" M C ";
}
function pastebinGet(code,path)
local sPath = shell.resolve(path);
local response = http.get("http://pastebin.com/raw.php?i="..textutils.urlEncode(code));
if response then
local contents = response.readAll();
response.close();
local file = fs.open(sPath,"w");
file.write(contents); -- THIS IS LINE 29 WHERE THE ERROR IS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
file.close();
return true;
else
return false;
end
end
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
pastebinGet("XjvCmnjQ","/.winMC/.OS/checkOSR");
shell.run("/.winMC/.OS/checkOSR");
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();
if not fs.exists("/.winMC/.OS/hasUser") then
fs.open("/.winMC/.OS/hasUser","w");
end
else
print("ERROR, USER ALREADY EXISTS, CHANGE USERNAME");
end
end
function login()
if not fs.exists("/.winMC/.OS/hasUser") then
createProfile();
local user = fs.open("/.winMC/.OS/hasUser","w");
user.close();
end
local usn;
local pass;
local tusn;
local tpass;
local uir;
local sucess = false;
while not sucess do
screenClear();
term.setCursorPos(1,1);
col(colors.green);
print("LOGIN");
print("USERNAME:");
term.setCursorPos(1,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"); tusn = uir.readLine();
tpass = uir.readLine();
if tusn == usn and tpass == pass then
print("LOGIN SUCESS");
user=usn;
userDir = "/.winMC/.user/"..usn
sucess = true;
else
col(colors.red);
print("INCORRECT USERNAME OR PASSWORD");
end
uir.close();
else
col(colors.red);
print("ERROR, USER FOLDER EXISTS, BUT USER INFO FILE DOES NOT");
end
else
col(colors.red);
print("INCORRECT USERNAME OR PASSWORD");
end
sleep(1);
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(1);
end
function drawDesktop()
term.clear();
local desktopBG = paintutils.loadImage("/.winMC/.OS/desktopBG");
paintutils.drawImage(desktopBG,0,2);
term.setCursorPos(1,h);
bgc(colors.green);
col(colors.black);
write("START");
end
screenClear();
startScreen();
screenClear();
checkOsReq();
--sleep(2);
--createProfile();
login();
drawDesktop();
sleep(2);