How do you declare user1? Where does it obtain its value from? Might need to see more of the code to help with this one.
Okay, it's my WIP OS so here's the code:
os.pullEvent = os.pullEventRaw
function filecreate(path)
local file = io.open(path, "a")
file:write()
file:close()
end
function foldercreate(dir)
fs.makeDir(dir)
end
function filedelete(dir)
fs.delete(dir)
end
function filecopy(from, to)
fs.copy(from, to)
end
function filemove(from, to)
fs.move(from, to)
end
function filewriteline(filename, line, text)
local file = io.open(filename, "r")
sContents = file:read() -- capture file in a string
file:close()
tContents = textutils.unserialize(sContents) -- convert string to table
table.insert(tContents, line, text)
end
function filereadline(filename, line)
local file = io.open(filename, "r")
sContents = file:read() -- capture file in a string
file:close()
if sContents then
tContents = textutils.unserialize(sContents) -- convert string to table
filetext = tContents[line]
elseif tContents[line] ~= nil then
filetext = ""
end
end
function filedeleteline(filename, line)
local file = io.open(filename, "r")
sContents = file:read() -- capture file in a string
file:close()
tContents = textutils.unserialize(sContents) -- convert string to table
table.remove(tContents, line)
end
function filesize(dir)
size = fs.getSize(dir)
end
w, h = term.getSize()
function printCentred( y, s )
local x = math.floor((w - string.len(s)) / 2)
term.setCursorPos(x,y)
term.clearLine()
term.write( s )
end
function drawregister()
filereadline("mineosuserdatauser1", 1)
user1 = filetext
filereadline("mineosuserdatauser1", 2)
user1pass = filetext
filereadline("mineosuserdatauser2", 1)
user2 = filetext
filereadline("mineosuserdatauser2", 2)
user2pass = filetext
filereadline("mineosuserdatauser3", 1)
user3 = filetext
filereadline("mineosuserdatauser3", 2)
user3pass = filetext
printCentred(math.floor(h/2) - 3, "---------------------")
printCentred(math.floor(h/2) - 2, "| MineOS Register |")
printCentred(math.floor(h/2) - 1, "---------------------")
if user1 == "" then
printCentred(math.floor(h/2) + 0, ((page2 == 1) and "> 1. <Empty> <") or "1. <Empty>")
else
printCentred(math.floor(h/2) + 0, ((page2 == 1) and "> 1. "..user1.." <") or "1. "..user1)
end
if user2 == "" then
printCentred(math.floor(h/2) + 1, ((page2 == 2) and "> 2. <Empty> <") or "2. <Empty>")
else
printCentred(math.floor(h/2) + 1, ((page2 == 2) and "> 1. "..user2.." <") or "1. "..user2)
end
if user3 == "" then
printCentred(math.floor(h/2) + 2, ((page2 == 3) and "> 3. <Empty> <") or "3. <Empty>")
else
printCentred(math.floor(h/2) + 2, ((page2 == 3) and "> 1. "..user3.." <") or "1. "..user3)
end
end
function register()
page2 = 1
foldercreate("mineos2/userdata")
filecreate("mineos2/userdata/user1")
filecreate("mineos2/userdata/user2")
filecreate("mineos2/userdata/user3")
while true do
local e,key = os.pullEventRaw("key")
if key == 17 or key == 200 then
if page2 > 1 then
page2 = page2 - 1
drawregister()
end
elseif key == 31 or key == 208 then
if page2 < 3 then
page2 = page2 + 1
drawregister()
end
elseif key == 28 then
break
end
if page2 == "1" then
elseif page2 == "2" then
register()
drawregister()
elseif page3 == "3" then
os.shutdown()
end
end
end
function drawmainmenu()
printCentred(math.floor(h/2) - 2, "MineOS Version 0.X")
printCentred(math.floor(h/2) - 1, "" )
printCentred(math.floor(h/2) + 0, ((page1 == 1) and "> Login <") or "Login")
printCentred(math.floor(h/2) + 1, ((page1 == 2) and "> Register <") or "Register")
printCentred(math.floor(h/2) + 2, ((page1 == 3) and "> Shutdown <") or "Shutdown")
printCentred(math.floor(h/2) + 3, "" )
end
print("Starting MineOS...")
print("")
sleep(1)
i = 0
repeat
i = i+1
print("Progress: "..i.."%")
sleep(0.04)
until i == 100
sleep(0.4)
term.clear()
page1 = 1
drawmainmenu()
while true do
local e,key = os.pullEventRaw("key")
if key == 17 or key == 200 then
if page1 > 1 then
page1 = page1 - 1
drawmainmenu()
end
elseif key == 31 or key == 208 then
if page1 < 3 then
page1 = page1 + 1
drawmainmenu()
end
elseif key == 28 then
if page1 == 1 then
elseif page1 == 2 then
term.clear()
register()
drawregister()
elseif page1 == 3 then
os.reboot()
end
end
if key == 28 then
break
end
end
How can I fix the problem? Oh, and there's still a lot of flaws, I haven't programmed areas yet.