Posted 23 December 2012 - 03:55 PM
Hey, for some reason I keep getting Copy:3: attempt to call nil
Copy is the program name.
Can anyone help me?
Copy is the program name.
Can anyone help me?
function resetScreen(quitQ,numberMade,label) -- function that resets the screen
term.clear() -- clears terminal
term.setCursorPos(1,1) -- sets cursor's position
if quitQ == true then --if quitQ is true, which starts out as false at line 10
if label == nil then
print("Current disk label: numerical")
elseif label == 0 then
print("Current disk label: None")
else
print("Current disk label: "..label)
end
print("Copies Made: "..tostring(numberMade)) -- prints total made
print("Press L to change the label.")
print("Press C to change the copying operation.")
print("Press Q to quit.")
end
end
function labeler()
while true do
resetScreen()
print("How would you like label the disks?\n(Enter number for selection.)")
print("1: Number (1, 2, 3..etc.)")
print("2: Custom Label")
print("3: No label")
local whatDo = read()
if whatDo == "1" then
label = nil
break
elseif whatDo == "2" then
resetScreen()
write("Enter the label: ")
label = read()
break
elseif whatDo == "3" then
label = 0
break
else
resetScreen()
print("Not a correct input, try again")
sleep(2)
end
end
resetScreen(quitQ,numberMade,label)
end
function copyChange()
while true do -- file I/O
resetScreen()
write("File to Copy: ")
fileIn = read() -- input file
write("Location/Name to copy to: ")
fileOut = read() -- output file
if fs.exists(fileIn) == false or fs.exists(fileOut) == true then -- if input file isn't there or if output file already exists
resetScreen()
print("Invalid inputs! Try again.")
print("(Maybe file incorrect file to be copied or file to be created is already there?)")
sleep(2)
else
break
end
end
resetScreen(quitQ,numberMade,label)
end
local side = "" -- side disk drive is on
local numberMade = 0 -- keeps track of how many were made
local quitQ = false -- quitQ is going to be short for quit-Question, meaning if false,
-- do not display the option to quit yet until able to
resetScreen(quitQ)
print("Insert a disk into the drive to be used.")
while true do
local event, param = os.pullEvent()
if event == "disk" then
side = param
break
end
end
labeler()
copyChange()
quitQ = true -- sets quitQ to true
-- it's always a good idea to keep comments orderly like you see here and above
while true do
resetScreen(quitQ,numberMade,label)
event, param = os.pullEvent()
if event == "disk" then
if fs.exists(fileOut) == true then -- if the file is already there (can't overwrite with cp!)
print("File already there! Please insert another disk.")
print("Press any button to eject and continue.")
while true do
local event = os.pullEvent()
if event == "char" or event == "key" then
disk.eject(side)
resetScreen(quitQ,numberMade)
break
end
end
else
fs.copy(fileIn, fileOut) -- copies with variables
if label ~= nil and label ~= 0 then
disk.setLabel(side, label)
elseif label == 0 then
---
else
disk.setLabel(side, tostring(numberMade + 1))
end
numberMade = numberMade + 1 -- add one to the count
disk.eject(side)
resetScreen(quitQ,numberMade,label)
end
end
if event == "char" and param == "l" then
labeler()
elseif event == "char" and param == "c" then
copyChange()
elseif event == "char" and param == "q" then -- test if quit button was pressed
break -- break exits the loop; jumps right down to the 'print'
end
end
quitQ = false
resetScreen(quitQ)
print("Bye!")
sleep(1)
resetScreen(quitQ)