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

RedPhonebook

Started by CastleMan2000, 25 April 2012 - 10:14 PM
CastleMan2000 #1
Posted 26 April 2012 - 12:14 AM
Hello. This is a phonebook program that you can enter the IDs of computers and it will save them.

Download: [attachment=198:RedPhonebook.txt]
Learning_inpaired #2
Posted 17 May 2012 - 05:00 AM
pleae put in to normal code im nooob
MathManiac #3
Posted 19 May 2012 - 12:31 AM
You should add pictures to see it in action. Also, I'm not a downloader, and source code in threads that doesn't require downloads is my thing.
Lyqyd #4
Posted 19 May 2012 - 02:57 AM
Some slight improvements:
  • Selecting the 'delete' entry would have always resulted in deletion of the entries.
  • Sufficient use of the program would have eventually overflowed the function stack.
  • shell.run() is bad.
  • tabulateCommon() is good.

term.clear()
term.setCursorPos(1, 5)
textutils.slowPrint("Initializing RedPhonebook...")
tEntries = {}
if fs.exists("//.phonebook.cfg") then
local file = io.open("//.phonebook.cfg", "r")
local sLine = file:read()
while sLine do
  table.insert(tEntries, sLine)
  sLine = file:read()
end
file:close()
else
textutils.slowPrint("Config file not found. Creating file.")
table.insert(tEntries, "")
end
sleep(1)
term.clear()
textutils.slowPrint("RedPhonebook Initialized.")
sleep(1)
term.clear()
local function writefile()
local file = io.open("//.phonebook.cfg", "w")
if file then
  for n, sLine in ipairs(tEntries) do
   file:write(sLine .. "n")
  end
  file:close()
  return true
end
return false
end
while true do
term.clear()
term.setCursorPos(1, 5)
print("What would you like to do?")
print("1 - Write Entry")
print("2 - Read Entries")
print("3 - Delete ALL Entries")
local phonebookOption = read()
if phonebookOption  == "1" then
  term.clear()
  print("Please enter the ID of the computer you wish to add, then it's name or owner's name.")
  local sID = read()
  local sName = read()
  table.insert(tEntries, "ID: "..sID.." Name: "..sName)
  writefile()
elseif phonebookOption == "2" then
  textutils.tabulateCommon(true, tEntries)
elseif phonebookOption == "3" then
  print("Are you sure you want to delete ALL phonebook entries?")
  print(" Y / N")
  local deleteAllEntriesPhonebook = string.lower(read())
  if deleteAllEntriesPhonebook == "y" then
   fs.delete("//.phonebook.cfg")
   for i=#tEntries, 1 do
    tEntries[i] = nil
   end
  end
end
end
CastleMan2000 #5
Posted 25 June 2012 - 01:30 AM
A table? How do tables work anyways? I think I want to use one as an inventory.
MysticT #6
Posted 25 June 2012 - 01:35 AM
A table? How do tables work anyways? I think I want to use one as an inventory.
From a simple google search: Tables tutorial
masaki84 #7
Posted 17 September 2012 - 04:48 AM
any way this could be hooked into Nitrogen Fingers email client. I'd love to be able to enter a persons name instead of Computer ID to email them.