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

[LUA][ERROR]"attempt to call nil" Notebook Script

Started by Skippy, 03 July 2014 - 10:29 PM
Skippy #1
Posted 04 July 2014 - 12:29 AM
I was trying out a notebook script I found earlier on the tekkit classic wiki (http://tekkitclassic.wikia.com/wiki/Tutorial/Notebook) and i've got it to open the first page. But when I type the numbers on the front page, I get these errors:

"1" - notebook:13: attempt to call nil
"2" - notebook:22: attempt to call nil
"3" - notebook:39: attempt to call nil


Here is the code I imputed:


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

Any help would be Great. Thanks!
Lyqyd #2
Posted 04 July 2014 - 12:40 AM
The script calls a clear() function without declaring one. You could probably just put this at the top to gain basic functionality:


local function clear()
  term.clear()
  term.setCursorPos(1, 1)
end
Skippy #3
Posted 04 July 2014 - 12:22 PM
I tried what you said and it comes up with the same messages.
Lyqyd #4
Posted 04 July 2014 - 04:30 PM
Please post the new code and the full text of the new error messages.
Bomb Bloke #5
Posted 04 July 2014 - 05:04 PM
If the errors really are the same, then that means you're still getting them because you ignored the bit about putting the new code at the top.