FANDOM


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

Start a Discussion Discussions about Tutorial/Notebook

  • Password

    5 messages
    • It's possible, yes. The thing though... Notbook is a "learning example" not an actual useful script.
    • just put a login program in the startup program then if it logs in corctley have it run the apiloader

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.