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

")" expected where it already is at

Started by makerimages, 23 December 2012 - 11:55 PM
makerimages #1
Posted 24 December 2012 - 12:55 AM
hi,

this code



...program
fs.exists("/OS/Users") while false do
term.clear()
term.setBackgroundColor(colors.lightBlue)
term.clear()
term.setBackgroundColor(colors.yellow)
local width=4
local size={term.getSize()}
for w=1,width do
  term.setCursorPos(1,size[2]-w+1)
  for x=1,size[1] do
    write(' ')
  end
end
term.setBackgroundColor(colors.lightBlue)
term.setCursorPos(1,1)
print("Hang on! It seems that you do not have a user account set up yet! Lets do that now!")
print("Please select a Username:")
local newname=read("")
fs.open("/OS/Users"...newname,"a")

...program

says that on the very last line of it a ")" is expected, how to fix?
remiX #2
Posted 24 December 2012 - 12:57 AM
Show us which line… the last line is '…program'
etopsirhc #3
Posted 24 December 2012 - 01:03 AM
the "last line" is farther down , witch could be where the problem is as no program should end in fs.open()
remiX #4
Posted 24 December 2012 - 01:04 AM
Yeah we can only help you if you show us the whole code..
makerimages #5
Posted 24 December 2012 - 01:15 AM
oh, i meant the last line of that piece i showd you
KaoS #6
Posted 24 December 2012 - 01:42 AM
why are there 3 '.'s between "/OS/Users" and newname? you only need 2 for concatenation
makerimages #7
Posted 24 December 2012 - 02:16 AM
That must be it, since I was unaware of the fact that you only need .. not … I wont be able to try it out till tomorrow though.
KaoS #8
Posted 24 December 2012 - 02:22 AM
cool. good luck
Zambonie #9
Posted 24 December 2012 - 06:06 AM
Ya,just to let you know,like I was making my calculater,It proboly gona mean you just forgot it there,or just that you made somekind of mistake tricking lua to think that you have to put something there.It happens with me sometimes.Gets kinda annoying though :/ .It just basicly means you made a mistake like what you did there. :P/>
ChunLing #10
Posted 24 December 2012 - 06:56 PM
Nobody's going to mention that there is no point in using fs.open unless you assign the returned table so that you can use it?
makerimages #11
Posted 24 December 2012 - 09:55 PM
Writing into the file comes right next.
remiX #12
Posted 24 December 2012 - 10:04 PM
He means that you need to do something like this:

fileHandle = fs.open("/OS/Users"...newname,"a")
-- Like this, you can write into it
fileHandle.write("-,-")
and not just
fs.open("/OS/Users"...newname,"a")
-- Like this, you can't write into it
makerimages #13
Posted 25 December 2012 - 12:23 AM
lets go on whit another error


--[[Copyright Makerimages, all of the code here was made by makerimages and you may not distribute this code without written premission]]--
--set screen colours
term.clear()
term.setCursorPos(1,1)
term.setBackgroundColor(colors.lightBlue)
term.clear()
term.setBackgroundColor(colors.yellow)
local width=4
local size={term.getSize()}
for w=1,width do
  term.setCursorPos(1,size[2]-w+1)
  for x=1,size[1] do
    write(' ')
  end
end
--load apis and set more colors
term.setBackgroundColor(colors.lightBlue)
term.setCursorPos(1,3)
os.loadAPI("/APIS/mOSapi")
mOSapi.Logo()
sleep(5)
term.clear()
term.setBackgroundColor(colors.lightBlue)
term.clear()
term.setBackgroundColor(colors.yellow)
local width=4
local size={term.getSize()}
for w=1,width do
  term.setCursorPos(1,size[2]-w+1)
  for x=1,size[1] do
    write(' ')
  end
end
--set more colours
term.clear()
term.setBackgroundColor(colors.lightBlue)
term.clear()
term.setBackgroundColor(colors.yellow)
local width=4
local size={term.getSize()}
for w=1,width do
  term.setCursorPos(1,size[2]-w+1)
  for x=1,size[1] do
    write(' ')
  end
  end
  --check for user dir
  fs.exists("/OS/Users") while false do
term.setBackgroundColor(colors.lightBlue)
term.setCursorPos(1,1)
print("Hang on! It seems that you do not have a user account set up yet! Lets do that now!")
print("Please select a Username:")
term.setTextColor(colors.white)
local newname=read("")
fs.makeDir("/OS/Users")
file=fs.open("/OS/Users"..newname,"a")
print("Please, choose a password to use in order to protect your account:")
local newpass=read("*")
n = tonumber(newpass)   -- try to convert it to a number
    if n == nil then
	  print("Whoops, cannot encrypt password")
    else
	  print("password set!")
   file.write(n)
    end
end

this is supposed to set screen colours and then chack if a directory exists, if it doesnt exist its supposed to make one and ask the user to seta username, then it is supposed to make a file in the /os/Users dir with the name of that username, then ask for password, turn it into a nr and write that in the file, it currently only sets the colors, then ends…
How to fix
remiX #14
Posted 25 December 2012 - 12:43 AM
I see you're using
fs.exists("/OS/Users")
to check if the folder exists, but that is wrong:
fs.isDIr("/OS/Users") -- use this to check if it exists

Edit: I'm not sure how you were trying to check if the folder existed or not with fs.exists("/OS/Users") while false do' But using an if statement is the best way:

Spoiler

if not fs.exists("/OS/Users") then
    fs.makeDir("/OS/Users")
    term.setBackgroundColor(colors.lightBlue)
    term.setCursorPos(1,1)
    print("Hang on! It seems that you do not have a user account set up yet! Lets do that now!")
    print("Please select a Username: ")
    term.setTextColor(colors.white)
    repeat
        term.setCursorPos(1,3)
        term.clearLine()
        s_newName = read()
    until s_newName ~= ""
    
    print("Please, choose a password to use in order to protect your account:")
    repeat
        term.setCursorPos(1,5)
        term.clearLine()
        s_newPassword = read()
    until s_newPassword ~= ""
    fileHandle = fs.open("/OS/Users"..s_newName,"w")
    fileHandle.write(s_newPassword)
    fileHandle.close() -- Always close a file after you're done with it.
else
    -- Code if it exists
end

The repeats I'm using for the new Username and new Passwords so you cannot set empty fields.
makerimages #15
Posted 25 December 2012 - 12:50 AM
edited code


--[[Copyright Makerimages, all of the code here was made by makerimages and you may not distribute this code without written premission]]--
--set screen colours
term.clear()
term.setCursorPos(1,1)
term.setBackgroundColor(colors.lightBlue)
term.clear()
term.setBackgroundColor(colors.yellow)
local width=4
local size={term.getSize()}
for w=1,width do
  term.setCursorPos(1,size[2]-w+1)
  for x=1,size[1] do
	write(' ')
  end
end
--load apis and set more colors
term.setBackgroundColor(colors.lightBlue)
term.setCursorPos(1,3)
os.loadAPI("/APIS/mOSapi")
mOSapi.Logo()
sleep(5)
term.clear()
term.setBackgroundColor(colors.lightBlue)
term.clear()
term.setBackgroundColor(colors.yellow)
local width=4
local size={term.getSize()}
for w=1,width do
  term.setCursorPos(1,size[2]-w+1)
  for x=1,size[1] do
	write(' ')
  end
end
  --check for user dir
  fs.isDir("/OS/Users") while false do
term.setBackgroundColor(colors.lightBlue)
term.setCursorPos(1,1)
print("Hang on! It seems that you do not have a user account set up yet! Lets do that now!")
print("Please select a Username:")
term.setTextColor(colors.white)
local newname=read("")
fs.makeDir("/OS/Users")
file=fs.open("/OS/Users" ..newname,"a")
print("Please, choose a password to use in order to protect your account:")
local newpass=read("*")
n = tonumber(newpass)   -- try to convert it to a number
	if n == nil then
	  print("Whoops, cannot encrypt password")
	else
	  print("password set!")
   file.write(n)
   file.close()
	end
end

term.setCursorPos(21,10)
print("Username:")
term.setCursorPos(21,11)
term.setbackgroundColor(colors.gray)
local loginname= read("")

now it skips the checking and new setup part

edit: also, no text is visible that i type in during local loginname= read("")
remiX #16
Posted 25 December 2012 - 12:55 AM
New setup part? What do you mean by that?

And check previous post, where I edited.
makerimages #17
Posted 25 December 2012 - 12:59 AM
new setup=That part where it asks for a username and stuff… ok, your stuff works, BUT it shows the passwor while i write it IT SHOULD NOT!!! and also it cuts of the please select a Username and choose a password in order to lines!! o mand it does not create a file in os/users, it creates a file in /os whit the name usersUSERNAMEHERE and the tonumber is not done and the password set is not shown and i cant see the username i try to login with once all done
remiX #18
Posted 25 December 2012 - 01:01 AM
I didn't test it and I was guessing the y lines :P/> It was showing the password because I forgot to make it read("*") Let me fix it for you quick
makerimages #19
Posted 25 December 2012 - 01:05 AM
alright, what about the rest??!?
remiX #20
Posted 25 December 2012 - 01:07 AM
Everything should be fine now


term.clear()
term.setCursorPos(1,1)
term.setBackgroundColor(colors.lightBlue)
if not fs.exists("/OS/Users") then
    fs.makeDir("/OS/Users")
    term.setCursorPos(1,1)
    print("Hang on! It seems that you do not have a user account set up yet! Lets do that now!")
    print("Please select a Username: ")
    term.setTextColor(colors.white)
    repeat
        term.setCursorPos(1,3)
        term.clearLine()
        write(" > ")
        s_newName = read()
    until s_newName ~= "" and not string.find(s_newName, " ")
    
    print("Please, choose a password to use in order to protect your account:")
    repeat
        term.setCursorPos(1,6)
        term.clearLine()
        write(" > ")
        s_newPassword = read("*")
    until s_newPassword ~= "" and not string.find(s_newPassword, " ")
    fileHandle = fs.open("/OS/Users/"..s_newName,"w")
    fileHandle.write(s_newPassword)
    fileHandle.close() -- Always close a file after you're done with it.
else
    fs.delete("/OS/Users")
end
makerimages #21
Posted 25 December 2012 - 01:30 AM
Will try out ASAP
makerimages #22
Posted 25 December 2012 - 02:31 AM
HUGE THANKS, it works