m 1 revision |
(No difference)
|
Welcome to a more advanced tutorial covering how to make a Notepad like program in ComputerCraft.
In this tutorial we'll make use of our Custom File API we made earlier. Remember to load it up with the Apiloader.
Now, create a folder named "notes" and a file named "Notebook".
-- Notebook
-- Written by Brainless243
-- Posted to The Tekkit Wiki on 24/10/2012
function clear() -- A function just to clear the screen and reset the mouse.
term.clear()
term.setCursorPos(1, 1)
end
clear()
done = false
print("Welcome to Notebook")
print("1. Read file")
print("2. Write file")
print("3. List documents")
print("4. Exit program") -- Press any of these numbers to activate that function
while true do
event, key = os.pullEvent("char")
if key == "1" then
clear()
print("Which file do you want to read?")
sFile = read()
print("Standby, opening file")
sleep(1)
print(file.read("notes/"..sFile, "a")) -- This is our API, remember?
return
elseif key == "2" then
clear()
print("What do you want to name the file? (No spaces)")
sFile = read()
print("Standby, opening file")
sleep(1)
clear()
print("Type exit() to quit editing document")
repeat
input = read()
if input == "exit()" then
done = true
else
file.write("notes/"..sFile, "w", input)-- This is also our api
end
until done -- Keep looping until the input is "exit()"
elseif key == "3" then
clear()
shell.run("list", "notes")
return
elseif key == "4" then
return
end
end
Phew, that was a long one right? But now you should have yourself a Notepad program.
Do you need a wiki for your Minecraft mod/gaming wiki? We'll host it for free! Contact us.