Jump to content




")" expected where it already is at


  • You cannot reply to this topic
21 replies to this topic

#1 makerimages

  • Members
  • 236 posts

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?

#2 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 24 December 2012 - 12:57 AM

Show us which line... the last line is '...program'

#3 etopsirhc

  • Members
  • 122 posts

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()

#4 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 24 December 2012 - 01:04 AM

Yeah we can only help you if you show us the whole code..

#5 makerimages

  • Members
  • 236 posts

Posted 24 December 2012 - 01:15 AM

oh, i meant the last line of that piece i showd you

#6 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 24 December 2012 - 01:42 AM

why are there 3 '.'s between "/OS/Users" and newname? you only need 2 for concatenation

#7 makerimages

  • Members
  • 236 posts

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.

#8 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 24 December 2012 - 02:22 AM

cool. good luck

#9 Zambonie

  • Members
  • 477 posts
  • LocationSpring Hill, Fl

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

#10 ChunLing

  • Members
  • 2,027 posts

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?

#11 makerimages

  • Members
  • 236 posts

Posted 24 December 2012 - 09:55 PM

Writing into the file comes right next.


#12 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

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


#13 makerimages

  • Members
  • 236 posts

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

#14 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

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

The repeats I'm using for the new Username and new Passwords so you cannot set empty fields.

#15 makerimages

  • Members
  • 236 posts

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("")

#16 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 25 December 2012 - 12:55 AM

New setup part? What do you mean by that?

And check previous post, where I edited.

#17 makerimages

  • Members
  • 236 posts

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

#18 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

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

#19 makerimages

  • Members
  • 236 posts

Posted 25 December 2012 - 01:05 AM

alright, what about the rest??!?

#20 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

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






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users