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

[Question] io.open doesn't work?

Started by Buss1000, 08 March 2012 - 12:40 AM
Buss1000 #1
Posted 08 March 2012 - 01:40 AM
Hey I have been learning LUA and my freind knows it too we made this program using the normal Lua program on my laptop.
I went home and copied it into my save disk on Minecraft and loaded it up.

-- Register
function register()
-- ask for name
print("Enter your user name.")
name = io.read()
-- ask for password
print("Enter your password.")
pass = io.read()
-- save to file
f = io.open("users.txt", "a+")
f:write("\n\n"..name.."\n"..pass)
f:close()
print("Saved to file! Thank you!")
end

-- List users
function list()
-- read list
g = io.open("users.txt", "r")
t = g:read("*a")
g:close()
-- print to screen
io.write(t)
end

-- Ask user for option
print("Would you like to:")
print("1. Register")
print("2. List users")
u = io.read()
if u == "1" then
register()
else
list()
end
-- end of program
print("\nEnd of program press enter.")
e = io.read()

It loads up all fine but if I try 1 it lets me put in user name and pass but it tells me "io:27: Unsupported mode".
If i try 2 it will tell me "register.lua:23: attempt to index ? (a nil value)".

Would this be Computercraft doesn't support io.write or io.read? It works fine on my Lua program.
Advert #2
Posted 08 March 2012 - 01:50 AM
Computercraft doesn't use C Lua; it uses LuaJ, and has a modifed io library.

You can type 'help io' and 'help fs' ingame for a list of functions.

I think that the mode "a" should be sufficient for what you're trying to do.
Buss1000 #3
Posted 08 March 2012 - 02:21 AM
Ok thanks I looked at the wiki a bit and found that out also you can't seem to use io.write() you only can use write(). I just used io.write() on my desktop because it doesn't take just write(). Now it works yay and now I can make whole programs that can write to text files and information will never be lost!