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

[Lua] [Error] Disk:3 String Expected in my SlimeOS Login program...

Started by mrSLIMEguy, 17 November 2012 - 10:16 AM
mrSLIMEguy #1
Posted 17 November 2012 - 11:16 AM
I am making a login system for my OS using floppy disks. I keep getting an error, in the disk api itself! Without knowing what code in my program is wrong, I cant fix it!
Error: disk:3 String Expected

Code:
Spoiler

os.loadAPI("/slimeos/apis/colourtxt")
while true do
function getDiskSide()
  sides = {"back","right","left","top","bottom"}
  for i=1, #sides do
   if disk.isPresent(sides[i]) and disk.getMountPath(perikit.sides[i]) == "/disk" then
	return perikit.sides[i]
   end
  end
end

term.clear()
term.setCursorPos(1,1)
colourtxt.printColour("SlimeOS Login Screen:", colours.white, colours.green)
colourtxt.printColour("What do you want to do?", colours.white, colours.blue)
print(" [1] Login with current disk")
print(" [2] Create new user with current disk")
print(" [3] Shutdown")
print("")
term.setTextColour(colours.yellow)
write("> ")
term.setTextColour(colours.white)
input = read()
if input == "1" then

elseif input == "2" then
  if not fs.exists("/disk/,") then
   --files = fs.list("/disk")
   --for i=1, #files do
   -- fs.delete(files[i])
   --end
   write("Username: ")
   usr = read()
   write("Password: ")
   pass1 = read("*")
   write("Confirm Password: ")
   pass2 = read("*")
   if pass1 == pass2 then
	print("Writing Data...")
	file = fs.open("/disk/,", "w")
	file.writeLine(pass2)
	disk.setLabel(getDiskSide(), usr)
	print("Data Written! Please Login:")
	sleep(2)
	file.close()
   else
	colourtxt.printColour("Passwords don't match!", colours.white, colours.red)
	sleep(2)
   end
  else
	colourtxt.printColour("Disk is already a user.",colours.white, colours.red)
	sleep(2)
  end
  elseif input == "3" then
  print("Goodbye")
  sleep(1)
  os.shutdown()
end
end

Colourtxt API (i dont think it has anything to do with the problem)
Spoiler

function printColour(text, oldcolour,newcolour)
--default = term.getTextColour()
term.setTextColour(newcolour)
print(text)
term.setTextColour(oldcolour)
end

Please help me!!!!!!!
Edited on 17 November 2012 - 10:18 AM
mrSLIMEguy #2
Posted 17 November 2012 - 11:18 AM
Edit was fixing spoilers

Edit was fixing spoilers
And title, lol
Lyqyd #3
Posted 17 November 2012 - 11:20 AM
You're trying to use a table you haven't defined. Either define the perikit table or remove the references to it.
mrSLIMEguy #4
Posted 17 November 2012 - 11:27 AM
OK, i changed it to this:

function getDiskSide()
  sides = {"back","right","left","top","bottom"}
  for i=1, #sides do
   if disk.isPresent(sides[i]) and disk.getMountPath(sides[i]) == "/disk" then
    return sides[i]
   end
  end
end


But it still says error when it labels the disk…. So i figured out where the error is, but not how to fix it…

OK, i changed it to this:

function getDiskSide()
  sides = {"back","right","left","top","bottom"}
  for i=1, #sides do
   if disk.isPresent(sides[i]) and disk.getMountPath(sides[i]) == "/disk" then
	return sides[i]
   end
  end
end


But it still says error when it labels the disk…. So i figured out where the error is, but not how to fix it…

Hang on, also that could be the function….
remiX #5
Posted 17 November 2012 - 12:09 PM
Do a debug test and make it print(getDiskSide())
Lyqyd #6
Posted 17 November 2012 - 02:00 PM
So, there's now an error when it labels the disk, rather than when it determines the side? Is the error shown the same error?
anonimo182 #7
Posted 17 November 2012 - 02:20 PM
Why are you opening a directory?

		file = fs.open("/disk/,", "w")
		file.writeLine(pass2)

Edit: 100th post! Scripter!

Edit 2: Sorry… I didn't saw that , in there…

Edit 3: use
function getDiskSide()
for i = 1, side in pairs(rs.getSides()) do
if disk.isPresent(side]) and disk.getMountPath(side) == "/disk" then
return side
end
end
end
remiX #8
Posted 17 November 2012 - 10:55 PM

function getDiskSide()
for i = 1, side in pairs(rs.getSides()) do
   if disk.isPresent(side]) and disk.getMountPath(side) == "/disk" then
	return side
   end
  end
end

If he is using tekkit, he can't use this.
Cloudy #9
Posted 18 November 2012 - 12:13 AM

function getDiskSide()
for i = 1, side in pairs(rs.getSides()) do
   if disk.isPresent(side]) and disk.getMountPath(side) == "/disk" then
	return side
   end
  end
end

If he is using tekkit, he can't use this.

Why not? Those functions have been there as long as disks have.
remiX #10
Posted 18 November 2012 - 12:21 AM
– snip

If he is using tekkit, he can't use this.

Why not? Those functions have been there as long as disks have.

Oh, I've heard around that tekkit doesn't have that function. Guess I'm wrong…

To OP: This seems to work, but I obviously had to remove the part where it prints using your api, because I don't have it. Try it out

Spoiler

sides = {"back","right","left","top","bottom"}
function getDiskSide()
    for i=1, #sides do
        if disk.isPresent(sides[i]) and disk.getMountPath(sides[i]) == "disk" then
            return sides[i]
        end
    end
end

function clean()
    term.setCursorPos(1,8) term.clearLine()
    term.setTextColour(colours.yellow)
    write("> ")
    r = read()
    term.setCursorPos(1,10) term.clearLine()
    term.setTextColour(colours.red)
    return r
end

term.clear()
term.setCursorPos(1,1)
term.setTextColour(colors.lightGray) print(" SlimeOS Login Screen:")
print(" What do you want to do?")
term.setTextColour(colours.red) print(" [1] Login with current disk")
print(" [2] Create new user with current disk")
print(" [3] Shutdown")
term.setTextColour(colours.yellow) print("Please type 1, 2 or 3")

while true do
    input = clean()
    if input == "1" then

    elseif input == "2" then
        if getDiskSide() then
            if not disk.getLabel(getDiskSide()) then
                --files = fs.list("/disk")
                --for i=1, #files do
                -- fs.delete(files[i])
                --end
                write("Username: ")
                usr = read()
                write("Password: ")
                pass1 = read("*")
                write("Confirm Password: ")
                pass2 = read("*")
                if pass1 == pass2 then
                    print("Writing Data...")
                    file = fs.open("/disk/"..usr, "w")
                    file.write(pass2)
                    file.close()
                    disk.setLabel(getDiskSide(), usr)
                    print("Data Written! Please Login:")
                    sleep(2)
                else
                    print("Passwords don't match!")
                    sleep(2)
                end
            else
                print("Disk is already a user.")
                sleep(2)
            end
        else
            print("No disk!")
            sleep(2)
        end
    elseif input == "3" then
        print("Goodbye")
        sleep(1)
        os.shutdown()
    end
end

-- Clean up
term.clear()
term.setCursorPos(1,1)
term.setTextColour(colours.white)
mrSLIMEguy #11
Posted 18 November 2012 - 12:27 PM
– snip
If he is using tekkit, he can't use this.
Why not? Those functions have been there as long as disks have.
Oh, I've heard around that tekkit doesn't have that function. Guess I'm wrong… To OP: This seems to work, but I obviously had to remove the part where it prints using your api, because I don't have it. Try it out
Spoiler
 sides = {"back","right","left","top","bottom"} function getDiskSide() for i=1, #sides do if disk.isPresent(sides[i]) and disk.getMountPath(sides[i]) == "disk" then return sides[i] end end end function clean() term.setCursorPos(1,8) term.clearLine() term.setTextColour(colours.yellow) write("> ") r = read() term.setCursorPos(1,10) term.clearLine() term.setTextColour(colours.red) return r end term.clear() term.setCursorPos(1,1) term.setTextColour(colors.lightGray) print(" SlimeOS Login Screen:") print(" What do you want to do?") term.setTextColour(colours.red) print(" [1] Login with current disk") print(" [2] Create new user with current disk") print(" [3] Shutdown") term.setTextColour(colours.yellow) print("Please type 1, 2 or 3") while true do input = clean() if input == "1" then elseif input == "2" then if getDiskSide() then if not disk.getLabel(getDiskSide()) then --files = fs.list("/disk") --for i=1, #files do -- fs.delete(files[i]) --end write("Username: ") usr = read() write("Password: ") pass1 = read("*") write("Confirm Password: ") pass2 = read("*") if pass1 == pass2 then print("Writing Data...") file = fs.open("/disk/"..usr, "w") file.write(pass2) file.close() disk.setLabel(getDiskSide(), usr) print("Data Written! Please Login:") sleep(2) else print("Passwords don't match!") sleep(2) end else print("Disk is already a user.") sleep(2) end else print("No disk!") sleep(2) end elseif input == "3" then print("Goodbye") sleep(1) os.shutdown() end end -- Clean up term.clear() term.setCursorPos(1,1) term.setTextColour(colours.white) 

1. The api is in the post…
2. It works!

xD

P.S I will put you in the credits. (for helping)
p.s.s I just used the function bit