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

OS-Help!

Started by _mika99_, 10 September 2015 - 03:17 PM
_mika99_ #1
Posted 10 September 2015 - 05:17 PM
So… I'm currently working on an OS called "WinOS". It's a pretty young project of about 270 lines of code. Currently I'm trying to make a "Add new User"-screen, in which the user writes in his username and password. I write all that data to a file called "%userdata" then, which looks like this after a fresh startup:

-
-
-
-
-
-
-
-
-
The maximum of users you can have is 3. That's why I programmed in an error which shuts down the PC when you try to add an fourth user. The only problem is, that I always get the error message, even if no users are registered! I really hope for a quick answer.

Here's the code (And yes, I know, it's not very organized):

---- Preparations ----
term.clear()
---- Draw Login Screen ----
--- Background ---
paintutils.drawFilledBox(1,1,51,19,colors.cyan)
--- User Boxes ---
paintutils.drawBox(6,2,15,11,colors.blue)
paintutils.drawBox(22,2,31,11,colors.blue)
paintutils.drawBox(38,2,47,11,colors.blue)
--- New User Button ---
paintutils.drawLine(3,16,3,18,colors.white)
paintutils.drawLine(2,17,4,17,colors.white)
--- Shutdown Button ---
paintutils.drawFilledBox(48,16,50,18,colors.red)
paintutils.drawLine(49,16,50,17,colors.white)
paintutils.drawLine(48,17,49,18,colors.white)
--- WinOS Text ---
-- W --
paintutils.drawLine(16,15,16,18,colors.white)
paintutils.drawLine(17,19,17,19,colors.white)
paintutils.drawLine(18,17,18,18,colors.white)
paintutils.drawLine(19,19,19,19,colors.white)
paintutils.drawLine(20,15,20,18,colors.white)
-- i --
paintutils.drawLine(22,17,22,19,colors.white)
paintutils.drawLine(22,15,22,15,colors.white)
-- n --
paintutils.drawLine(24,17,24,19,colors.white)
paintutils.drawLine(24,17,26,17,colors.white)
paintutils.drawLine(27,18,27,19,colors.white)
-- O --
paintutils.drawLine(29,16,29,18,colors.white)
paintutils.drawLine(30,15,31,15,colors.white)
paintutils.drawLine(30,19,31,19,colors.white)
paintutils.drawLine(32,16,32,18,colors.white)
-- S --
paintutils.drawLine(35,15,36,15,colors.white)
paintutils.drawLine(34,16,36,18,colors.white)
paintutils.drawLine(34,19,35,19,colors.white)
---- Userbox Filling ----
--- Perparations ---
local userdata = fs.open("%userdata", "r")
local firstUDLine = userdata.readLine()
if firstUDLine == "" then
  userdata.close()
  local userdata = fs.open("%userdata", "w")
 
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
 
  userdata.close()
  local userdata = fs.open("%userdata", "r")
end
--- Actual Filling ---
-- User 1 --
userdata.readLine()
if userdata.readLine() == "red" then
  paintutils.drawFilledBox(7,3,14,10,colors.red)
elseif userdata.readLine() == "blue" then
  paintutils.drawFilledBox(7,3,14,10,colors.blue)
elseif userdata.readLine() == "green" then
  paintutils.drawFilledBox(7,3,14,10,colors.green)
else
  paintutils.drawFilledBox(7,3,14,10,colors.white)
end
-- User 2 --
userdata.readLine()
if userdata.readLine() == "red" then
  paintutils.drawFilledBox(23,3,30,10,colors.red)
elseif userdata.readLine() == "blue" then
  paintutils.drawFilledBox(23,3,30,10,colors.blue)
elseif userdata.readLine() == "green" then
  paintutils.drawFilledBox(23,3,30,10,colors.green)
else
  paintutils.drawFilledBox(23,3,30,10,colors.white)
end
-- User 3 --
userdata.readLine()
if userdata.readLine() == "red" then
  paintutils.drawFilledBox(39,3,46,10,colors.red)
elseif userdata.readLine() == "blue" then
  paintutils.drawFilledBox(39,3,46,10,colors.blue)
elseif userdata.readLine() == "green" then
  paintutils.drawFilledBox(39,3,46,10,colors.green)
else
  paintutils.drawFilledBox(39,3,46,10,colors.white)
end
while true do
  local event, button, x, y = os.pullEvent("mouse_click")
  if button == 1 then
    if x > 47 and x < 51 and y > 15 and y < 19 then
	  term.clear()
	  paintutils.drawFilledBox(1,1,51,19,colors.cyan)
	  term.setCursorPos(19,10)
	  term.write("Shutting down |")
	  term.setCursorBlink(false)
	  term.setCursorPos(33,10)
	  sleep(0.1)
	  term.write("/")
	  term.setCursorPos(33,10)
	  sleep(0.1)
   term.write("-")
	  term.setCursorPos(33,10)
	  sleep(0.1)
   term.write("\\")
	  term.setCursorPos(33,10)
	  sleep(0.1)
   term.write("|")
	  term.setCursorPos(33,10)
	  sleep(0.1)
   term.write("/")
	  term.setCursorPos(33,10)
	  sleep(0.1)
   term.write("-")
	  term.setCursorPos(33,10)
	  sleep(0.1)
   term.write("\\")
	  term.setCursorPos(33,10)
	  sleep(0.1)
   term.write("|")
	  term.setCursorPos(33,10)
	  sleep(0.1)
   term.write("/")
	  term.setCursorPos(33,10)
	  sleep(0.1)
	  os.shutdown()
elseif x > 1 and x < 5 and y > 15 and y < 19 then
while true do
   term.clear()
   paintutils.drawFilledBox(1,1,51,19,colors.cyan)
   term.setCursorPos(19,4)
   term.write("Add a new User:")
  
   term.setCursorPos(13,7)
   term.write("Username")
  
   term.setCursorPos(13,9)
   term.write("Password")
  
   paintutils.drawFilledBox(2,14,8,16,colors.red)
   term.setCursorPos(3,15)
   term.write("Abort")
  
   paintutils.drawFilledBox(43,14,50,16,colors.green)
   term.setCursorPos(45,15)
   term.write("Done")
  
   term.setCursorPos(2,18)
   term.write("Restart required after every action in this menu!")
  
   term.setCursorPos(22,7)
   local newUsername = read()
  
   term.setCursorPos(22,9)
   local newPassword = read("*")
  
   term.setCursorPos(0,0)
  
   if newUsername == "-" or newPassword == "-" then
  term.setCursorBlink(true)
  term.setTextColor(colors.red)
  term.setBackgroundColor(colors.cyan)
  term.setCursorPos(22,11)
  term.write("Invalid Password or Username!")
 
  sleep(5)
	  else
	 break
	  end
end

   local userdata = fs.open("%userdata", "r")
   if userdata.readLine == "-" then
	 userdata.close()
  local userdata = fs.open("%userdata", "w")
  userdata.writeLine(newUsername)
  userdata.writeLine(newPassword)
  userdata.writeLine("red")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.close()
	  else
	 userdata.readLine()
  userdata.readLine()
  if userdata.readLine == "-" then
    userdata.close()
    local userdata = fs.open("%userdata", "r")
    local Line1 = userdata.readLine()
    local Line2 = userdata.readLine()
    local Line3 = userdata.readLine()
    userdata.close()
    local userdata = fs.open("%userdata", "w")
    userdata.writeLine(Line1)
    userdata.writeLine(Line2)
    userdata.writeLine(Line3)
    userdata.writeLine(newUsername)
    userdata.writeLine(newPassword)
    userdata.writeLine("green")
    userdata.close()
  else
    userdata.readLine()
    userdata.readLine()
    if userdata.readLine == "-" then
	  userdata.close()
   local userdata = fs.open("%userdata", "r")
   local Line1 = userdata.readLine()
   local Line2 = userdata.readLine()
   local Line3 = userdata.readLine()
   local Line4 = userdata.readLine()
   local Line5 = userdata.readLine()
   local Line6 = userdata.readLine()
   userdata.close()
   local userdata = fs.open("%userdata", "w")
   userdata.writeLine(Line1)
   userdata.writeLine(Line2)
   userdata.writeLine(Line3)
   userdata.writeLine(Line4)
   userdata.writeLine(Line5)
   userdata.writeLine(Line6)
   userdata.writeLine(newUsername)
	  userdata.writeLine(newPassword)
   userdata.writeLine("blue")
   userdata.close()
	   else
	  term.setCursorBlink(true)
   term.setTextColor(colors.red)
	  term.setBackgroundColor(colors.cyan)
   term.setCursorPos(12,15)
   term.write("Error! Computer restarting...")
   term.setCursorBlink(false)
  
   sleep(3)
  
   os.shutdown()
   end
    end
  end
end
end
end
KingofGamesYami #2
Posted 10 September 2015 - 05:52 PM
There are a number of problems with your code…

1 - if 'firstUDLine' equals "", userdata will closed when you get past that if statement.
Fix:

local userdata = fs.open("%userdata", "r")
local firstUDLine = userdata.readLine()
if firstUDLine == "" then
  userdata.close()
  local userdata = fs.open("%userdata", "w")

  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")

  userdata.close()
  userdata = fs.open("%userdata", "r") --#userdata has already been declared local to your script, don't make it local to this statement!
end

2 - each time you call userdata.readLine, it's going to go to the next line. Thus, this:
if userdata.readLine() == "red" then
  paintutils.drawFilledBox(7,3,14,10,colors.red)
elseif userdata.readLine() == "blue" then
  paintutils.drawFilledBox(7,3,14,10,colors.blue)
elseif userdata.readLine() == "green" then
  paintutils.drawFilledBox(7,3,14,10,colors.green)
else
  paintutils.drawFilledBox(7,3,14,10,colors.white)
end
..will likely move 3 lines if the line did not contain "red".

Fix:

local c = { red = colors.red, blue = colors.blue, green = colors.green }
paintutils.drawFilledBox( 7, 3, 14, 10, c[ userdata.readLine() ] or colors.white )
Edited on 10 September 2015 - 03:57 PM
_mika99_ #3
Posted 10 September 2015 - 06:27 PM
Thanks for your answer, but sadly this didn't solve any of my problems, it only got me some new ones.

1 - if 'firstUDLine' equals "", userdata will closed when you get past that if statement.
Fix:

local userdata = fs.open("%userdata", "r")
local firstUDLine = userdata.readLine()
if firstUDLine == "" then
userdata.close()
local userdata = fs.open("%userdata", "w")

userdata.writeLine("-")
userdata.writeLine("-")
userdata.writeLine("-")
userdata.writeLine("-")
userdata.writeLine("-")
userdata.writeLine("-")
userdata.writeLine("-")
userdata.writeLine("-")
userdata.writeLine("-")

userdata.close()
userdata = fs.open("%userdata", "r") #userdata has already been declared local to your script, don't make it local to this statement!
end
This wasn't exactly right. This works for me although:

if fs.exists("%userdata") == false then
  local createUserdata = fs.open("%userdata", "w")
  createUserdata.close()
end

local userdata = fs.open("%userdata", "r")
local firstUDLine = userdata.readLine()
if firstUDLine == nil then
  userdata.close()
  local userdata = fs.open("%userdata", "w")

  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")

  userdata.close()
  userdata = fs.open("%userdata", "r")
end


2 - each time you call userdata.readLine, it's going to go to the next line. Thus, this:
if userdata.readLine() == "red" then
paintutils.drawFilledBox(7,3,14,10,colors.red)
elseif userdata.readLine() == "blue" then
paintutils.drawFilledBox(7,3,14,10,colors.blue)
elseif userdata.readLine() == "green" then
paintutils.drawFilledBox(7,3,14,10,colors.green)
else
paintutils.drawFilledBox(7,3,14,10,colors.white)
end
..will likely move 3 lines if the line did not contain "red".

Fix:
local c = { red = colors.red, blue = colors.blue, green = colors.green }
paintutils.drawFilledBox( 7, 3, 14, 10, c[ userdata.readLine() ] or colors.white )

I replaced my old code for every User with your fixed code and edited the paintutils coordinates. Result: User 1's color displays in User 2's picture and the other ones don't display at all.

Help :(/>
KingofGamesYami #4
Posted 10 September 2015 - 06:31 PM
There are probably more errors in the code than I found, I'd not read through the whole thing. If you could post the updated code so I know how you tried to use my fixes, I might be able to figure out the problem.
_mika99_ #5
Posted 10 September 2015 - 06:35 PM
There you go, that's my new code:

---- Preparations ----
term.clear()
---- Draw Login Screen ----
--- Background ---
paintutils.drawFilledBox(1,1,51,19,colors.cyan)
--- User Boxes ---
paintutils.drawBox(6,2,15,11,colors.blue)
paintutils.drawBox(22,2,31,11,colors.blue)
paintutils.drawBox(38,2,47,11,colors.blue)
--- New User Button ---
paintutils.drawLine(3,16,3,18,colors.white)
paintutils.drawLine(2,17,4,17,colors.white)
--- Shutdown Button ---
paintutils.drawFilledBox(48,16,50,18,colors.red)
paintutils.drawLine(49,16,50,17,colors.white)
paintutils.drawLine(48,17,49,18,colors.white)
--- WinOS Text ---
-- W --
paintutils.drawLine(16,15,16,18,colors.white)
paintutils.drawLine(17,19,17,19,colors.white)
paintutils.drawLine(18,17,18,18,colors.white)
paintutils.drawLine(19,19,19,19,colors.white)
paintutils.drawLine(20,15,20,18,colors.white)
-- i --
paintutils.drawLine(22,17,22,19,colors.white)
paintutils.drawLine(22,15,22,15,colors.white)
-- n --
paintutils.drawLine(24,17,24,19,colors.white)
paintutils.drawLine(24,17,26,17,colors.white)
paintutils.drawLine(27,18,27,19,colors.white)
-- O --
paintutils.drawLine(29,16,29,18,colors.white)
paintutils.drawLine(30,15,31,15,colors.white)
paintutils.drawLine(30,19,31,19,colors.white)
paintutils.drawLine(32,16,32,18,colors.white)
-- S --
paintutils.drawLine(35,15,36,15,colors.white)
paintutils.drawLine(34,16,36,18,colors.white)
paintutils.drawLine(34,19,35,19,colors.white)
---- Userbox Filling ----
--- Perparations ---
if fs.exists("%userdata") == false then
  local createUserdata = fs.open("%userdata", "w")
  createUserdata.close()
end
 
local userdata = fs.open("%userdata", "r")
local firstUDLine = userdata.readLine()
if firstUDLine == nil then
  userdata.close()
  local userdata = fs.open("%userdata", "w")
 
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
 
  userdata.close()
  userdata = fs.open("%userdata", "r")
end
--- Actual Filling ---
-- User 1 7, 3, 14, 10 --
local c = { red = colors.red, blue = colors.blue, green = colors.green }
paintutils.drawFilledBox(7,3,14,10, c[ userdata.readLine() ] or colors.white )
-- User 2 23,3,30,10 --
paintutils.drawFilledBox(23,3,30,10, c[ userdata.readLine() ] or colors.white )
-- User 3 39,3,46,10 --
paintutils.drawFilledBox(39,3,46,10, c[ userdata.readLine() ] or colors.white )
while true do
  local event, button, x, y = os.pullEvent("mouse_click")
  if button == 1 then
    if x > 47 and x < 51 and y > 15 and y < 19 then
	  term.clear()
	  paintutils.drawFilledBox(1,1,51,19,colors.cyan)
	  term.setCursorPos(19,10)
	  term.write("Shutting down |")
	  term.setCursorBlink(false)
	  term.setCursorPos(33,10)
	  sleep(0.1)
	  term.write("/")
	  term.setCursorPos(33,10)
	  sleep(0.1)
   term.write("-")
	  term.setCursorPos(33,10)
	  sleep(0.1)
   term.write("\\")
	  term.setCursorPos(33,10)
	  sleep(0.1)
   term.write("|")
	  term.setCursorPos(33,10)
	  sleep(0.1)
   term.write("/")
	  term.setCursorPos(33,10)
	  sleep(0.1)
   term.write("-")
	  term.setCursorPos(33,10)
	  sleep(0.1)
   term.write("\\")
	  term.setCursorPos(33,10)
	  sleep(0.1)
   term.write("|")
	  term.setCursorPos(33,10)
	  sleep(0.1)
   term.write("/")
	  term.setCursorPos(33,10)
	  sleep(0.1)
	  os.shutdown()
elseif x > 1 and x < 5 and y > 15 and y < 19 then
while true do
   term.clear()
   paintutils.drawFilledBox(1,1,51,19,colors.cyan)
   term.setCursorPos(19,4)
   term.write("Add a new User:")
  
   term.setCursorPos(13,7)
   term.write("Username")
  
   term.setCursorPos(13,9)
   term.write("Password")
  
   paintutils.drawFilledBox(2,14,8,16,colors.red)
   term.setCursorPos(3,15)
   term.write("Abort")
  
   paintutils.drawFilledBox(43,14,50,16,colors.green)
   term.setCursorPos(45,15)
   term.write("Done")
  
   term.setCursorPos(2,18)
   term.write("Restart required after every action in this menu!")
  
   term.setCursorPos(22,7)
   local newUsername = read()
  
   term.setCursorPos(22,9)
   local newPassword = read("*")
  
   term.setCursorPos(0,0)
  
   if newUsername == "-" or newPassword == "-" then
  term.setCursorBlink(true)
  term.setTextColor(colors.red)
  term.setBackgroundColor(colors.cyan)
  term.setCursorPos(22,11)
  term.write("Invalid Password or Username!")
 
  sleep(5)
	  else
	 break
	  end
end

   local userdata = fs.open("%userdata", "r")
   if userdata.readLine == "-" then
	 userdata.close()
  local userdata = fs.open("%userdata", "w")
  userdata.writeLine(newUsername)
  userdata.writeLine(newPassword)
  userdata.writeLine("red")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.close()
	  else
	 userdata.readLine()
  userdata.readLine()
  if userdata.readLine == "-" then
    userdata.close()
    local userdata = fs.open("%userdata", "r")
    local Line1 = userdata.readLine()
    local Line2 = userdata.readLine()
    local Line3 = userdata.readLine()
    userdata.close()
    local userdata = fs.open("%userdata", "w")
    userdata.writeLine(Line1)
    userdata.writeLine(Line2)
    userdata.writeLine(Line3)
    userdata.writeLine(newUsername)
    userdata.writeLine(newPassword)
    userdata.writeLine("green")
    userdata.close()
  else
    userdata.readLine()
    userdata.readLine()
    if userdata.readLine == "-" then
	  userdata.close()
   local userdata = fs.open("%userdata", "r")
   local Line1 = userdata.readLine()
   local Line2 = userdata.readLine()
   local Line3 = userdata.readLine()
   local Line4 = userdata.readLine()
   local Line5 = userdata.readLine()
   local Line6 = userdata.readLine()
   userdata.close()
   local userdata = fs.open("%userdata", "w")
   userdata.writeLine(Line1)
   userdata.writeLine(Line2)
   userdata.writeLine(Line3)
   userdata.writeLine(Line4)
   userdata.writeLine(Line5)
   userdata.writeLine(Line6)
   userdata.writeLine(newUsername)
	  userdata.writeLine(newPassword)
   userdata.writeLine("blue")
   userdata.close()
	   else
	  term.setCursorBlink(true)
   term.setTextColor(colors.red)
	  term.setBackgroundColor(colors.cyan)
   term.setCursorPos(12,15)
   term.write("Error! Computer restarting...")
   term.setCursorBlink(false)
  
   sleep(3)
  
   os.shutdown()
   end
    end
  end
end
end
end
KingofGamesYami #6
Posted 10 September 2015 - 07:55 PM
So I did a bunch of stuff to the top half of your code, it works now… I think.

Spoiler

---- Preparations ----
term.clear()
---- Draw Login Screen ----
--- Background ---
paintutils.drawFilledBox(1,1,51,19,colors.cyan)
--- User Boxes ---
paintutils.drawBox(6,2,15,11,colors.blue)
paintutils.drawBox(22,2,31,11,colors.blue)
paintutils.drawBox(38,2,47,11,colors.blue)
--- New User Button ---
paintutils.drawLine(3,16,3,18,colors.white)
paintutils.drawLine(2,17,4,17,colors.white)
--- Shutdown Button ---
paintutils.drawFilledBox(48,16,50,18,colors.red)
paintutils.drawLine(49,16,50,17,colors.white)
paintutils.drawLine(48,17,49,18,colors.white)
--- WinOS Text ---
-- W --
paintutils.drawLine(16,15,16,18,colors.white)
paintutils.drawLine(17,19,17,19,colors.white)
paintutils.drawLine(18,17,18,18,colors.white)
paintutils.drawLine(19,19,19,19,colors.white)
paintutils.drawLine(20,15,20,18,colors.white)
-- i --
paintutils.drawLine(22,17,22,19,colors.white)
paintutils.drawLine(22,15,22,15,colors.white)
-- n --
paintutils.drawLine(24,17,24,19,colors.white)
paintutils.drawLine(24,17,26,17,colors.white)
paintutils.drawLine(27,18,27,19,colors.white)
-- O --
paintutils.drawLine(29,16,29,18,colors.white)
paintutils.drawLine(30,15,31,15,colors.white)
paintutils.drawLine(30,19,31,19,colors.white)
paintutils.drawLine(32,16,32,18,colors.white)
-- S --
paintutils.drawLine(35,15,36,15,colors.white)
paintutils.drawLine(34,16,36,18,colors.white)
paintutils.drawLine(34,19,35,19,colors.white)
---- Userbox Filling ----
--- Perparations ---

local userdata = fs.open(".userdata", "r")
if not userdata or userdata.readLine() ~= "--UserData--" then
  local userdata = fs.open(".userdata", "w")
  userdata.write( "--UserData--\n" .. string.rep( "--\n", 9 ) )
  userdata.close()
end
userdata = fs.open(".userdata", "r")
--- Actual Filling ---
-- User 1 7, 3, 14, 10 --
userdata.readLine() --remove comment on top of .userdata
local function advance()
	for i = 1, 2 do
		userdata.readLine()
	end
end
local c = { red = colors.red, blue = colors.blue, green = colors.green }
--User 1 7, 3, 14, 10--
advance() --move two down
paintutils.drawFilledBox(7,3,14,10, c[ userdata.readLine() ] or colors.white )
-- User 2 23,3,30,10 --
advance()
paintutils.drawFilledBox(23,3,30,10, c[ userdata.readLine() ] or colors.white )
-- User 3 39,3,46,10 --
advance()
paintutils.drawFilledBox(39,3,46,10, c[ userdata.readLine() ] or colors.white )
--After this point I haven't modified anything because formatting is hard to read!!--
while true do
  local event, button, x, y = os.pullEvent("mouse_click")
  if button == 1 then
    if x > 47 and x < 51 and y > 15 and y < 19 then
	  term.clear()
	  paintutils.drawFilledBox(1,1,51,19,colors.cyan)
	  term.setCursorPos(19,10)
	  term.write("Shutting down |")
	  term.setCursorBlink(false)
	  term.setCursorPos(33,10)
	  sleep(0.1)
	  term.write("/")
	  term.setCursorPos(33,10)
	  sleep(0.1)
   term.write("-")
	  term.setCursorPos(33,10)
	  sleep(0.1)
   term.write("\\")
	  term.setCursorPos(33,10)
	  sleep(0.1)
   term.write("|")
	  term.setCursorPos(33,10)
	  sleep(0.1)
   term.write("/")
	  term.setCursorPos(33,10)
	  sleep(0.1)
   term.write("-")
	  term.setCursorPos(33,10)
	  sleep(0.1)
   term.write("\\")
	  term.setCursorPos(33,10)
	  sleep(0.1)
   term.write("|")
	  term.setCursorPos(33,10)
	  sleep(0.1)
   term.write("/")
	  term.setCursorPos(33,10)
	  sleep(0.1)
	  os.shutdown()
elseif x > 1 and x < 5 and y > 15 and y < 19 then
while true do
   term.clear()
   paintutils.drawFilledBox(1,1,51,19,colors.cyan)
   term.setCursorPos(19,4)
   term.write("Add a new User:")

   term.setCursorPos(13,7)
   term.write("Username")

   term.setCursorPos(13,9)
   term.write("Password")

   paintutils.drawFilledBox(2,14,8,16,colors.red)
   term.setCursorPos(3,15)
   term.write("Abort")

   paintutils.drawFilledBox(43,14,50,16,colors.green)
   term.setCursorPos(45,15)
   term.write("Done")

   term.setCursorPos(2,18)
   term.write("Restart required after every action in this menu!")

   term.setCursorPos(22,7)
   local newUsername = read()

   term.setCursorPos(22,9)
   local newPassword = read("*")

   term.setCursorPos(0,0)

   if newUsername == "-" or newPassword == "-" then
  term.setCursorBlink(true)
  term.setTextColor(colors.red)
  term.setBackgroundColor(colors.cyan)
  term.setCursorPos(22,11)
  term.write("Invalid Password or Username!")

  sleep(5)
	  else
	 break
	  end
end

   local userdata = fs.open(".userdata", "r")
   if userdata.readLine == "-" then
	 userdata.close()
  local userdata = fs.open(".userdata", "w")
  userdata.writeLine(newUsername)
  userdata.writeLine(newPassword)
  userdata.writeLine("red")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.writeLine("-")
  userdata.close()
	  else
	 userdata.readLine()
  userdata.readLine()
  if userdata.readLine == "-" then
    userdata.close()
    local userdata = fs.open(".userdata", "r")
    local Line1 = userdata.readLine()
    local Line2 = userdata.readLine()
    local Line3 = userdata.readLine()
    userdata.close()
    local userdata = fs.open(".userdata", "w")
    userdata.writeLine(Line1)
    userdata.writeLine(Line2)
    userdata.writeLine(Line3)
    userdata.writeLine(newUsername)
    userdata.writeLine(newPassword)
    userdata.writeLine("green")
    userdata.close()
  else
    userdata.readLine()
    userdata.readLine()
    if userdata.readLine == "-" then
	  userdata.close()
   local userdata = fs.open(".userdata", "r")
   local Line1 = userdata.readLine()
   local Line2 = userdata.readLine()
   local Line3 = userdata.readLine()
   local Line4 = userdata.readLine()
   local Line5 = userdata.readLine()
   local Line6 = userdata.readLine()
   userdata.close()
   local userdata = fs.open(".userdata", "w")
   userdata.writeLine(Line1)
   userdata.writeLine(Line2)
   userdata.writeLine(Line3)
   userdata.writeLine(Line4)
   userdata.writeLine(Line5)
   userdata.writeLine(Line6)
   userdata.writeLine(newUsername)
	  userdata.writeLine(newPassword)
   userdata.writeLine("blue")
   userdata.close()
	   else
	  term.setCursorBlink(true)
   term.setTextColor(colors.red)
	  term.setBackgroundColor(colors.cyan)
   term.setCursorPos(12,15)
   term.write("Error! Computer restarting...")
   term.setCursorBlink(false)

   sleep(3)

   os.shutdown()
   end
    end
  end
end
end
end

.userdata

--UserData--
-
-
blue
-
-
red
-
-
green
Edited on 10 September 2015 - 05:55 PM
_mika99_ #7
Posted 10 September 2015 - 09:01 PM
Well, it kinda works, it just overwrites the .userdata on every startup with this:

--UserData--
--
--
--
--
--
--
--
--
--
I dont understand why there is so much going wrong with my code. :(/> xD
KingofGamesYami #8
Posted 10 September 2015 - 09:36 PM
It shouldn't… I tested my code myself. For me, it doesn't overwrite the .userdata file if –UserData– is left at the top.
_mika99_ #9
Posted 10 September 2015 - 11:49 PM
if –UserData– is left at the top.
So that's what I did wrong, I deleted the –UserData– on top… >_<