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

probably another dumb mistake on my part :(

Started by Wooki_inthetrees, 15 August 2014 - 10:39 AM
Wooki_inthetrees #1
Posted 15 August 2014 - 12:39 PM
another startup:10: attempt to call nil error im not quite sure what to say anyway here's the code.


local q1
local q2
local q3
local q4
if fs.exists("disk/app") then write("Remove current disk and reboot")
os.reboot()
else
print("Why are you applying to become staff of Oceanic Cove:")
q1 = read()
clear()

print("How old are you?:")
q1 = read()
clear()

print("do you have or can you get ts3(teamspeak)")
q3 = read()
clear()

print("What do you think makes you more Valuable then other Applicants?:")
q4 = read()
clear()

end
local f = fs.open("doorlock-settings")
f.writeLine(q1)
f.writeLine(q2)
f.writeLine(q3)
f.writeLine(q4)
f.close()
print("Remove drive and throw under the computer thanks for your application")
InputUsername #2
Posted 15 August 2014 - 01:09 PM
First of all, put your code inside
 
tags. PLEASE.

Secondly, you are trying to call a clear() function on line 10 and a few lines below that too. The clear() function doesn't exist, perhaps you mean term.clear()?

EDIT: re-reading the code, I spotted another error; fs.open requires two arguments, the file and the mode (r for read, w for write or a for append). Example: fs.open("doorlock-settings","w")
Also, I personally think using term.write() instead of write() is better, but that's up to you.
Edited on 15 August 2014 - 11:13 AM
natedogith1 #3
Posted 15 August 2014 - 01:28 PM
Also, I personally think using term.write() instead of write() is better, but that's up to you.
There is a difference between term.write() and write(), namely in that write() handles new lines and wrapping for you. Though there is the issue that where the write is used (and I'm not sure why it's not print), the screen will be cleared by the reboot before the user can read the message (and then this will repeat over and over because this is the startup program…)
Wooki_inthetrees #4
Posted 15 August 2014 - 01:33 PM
changing a few things around and some errors i just noticed then i will repost code if im still having issues :P/>
Wooki_inthetrees #5
Posted 15 August 2014 - 01:43 PM
im sorry but exactly how are the code tags thing used ?
theoriginalbit #6
Posted 15 August 2014 - 01:44 PM
on the formatting toolbar there is a button that looks like <> either press that and paste in your code, or manually type [code][/code] around your code.
Edited on 15 August 2014 - 11:45 AM
Wooki_inthetrees #7
Posted 15 August 2014 - 01:59 PM

local q1
local q2
local q3
local q4
if fs.exists("disk/app") then write("Remove current disk and reboot")
os.reboot()
else
		print("Why are you applying to become staff of Oceanic Cove:")
		q1 = read()
		term.clear()
	  
		print("How old are you?:")
		q2 = read()
		term.clear()
	  
		print("do you have or can you get ts3(teamspeak)")
		q3 = read()
		term.clear()

		print("What do you think makes you more Valuable then other Applicants?:")
		q4 = read()
		term.clear()
end
local f = fs.open("disk/app", "w")
f.writeLine(q1)
f.writeLine(q2)
f.writeLine(q3)
f.writeLine(q4)
f.close()
print("Remove disk and throw under the computer thanks for your application")

ok so what im attempting to do is set it so it asks the questions (q1,q2,q3,q4) and reads the input and writes that in another program with the program being on a disk.

not sure but im getting a startup:26: attempt to index? (a nil value)

Also, I personally think using term.write() instead of write() is better, but that's up to you.
There is a difference between term.write() and write(), namely in that write() handles new lines and wrapping for you. Though there is the issue that where the write is used (and I'm not sure why it's not print), the screen will be cleared by the reboot before the user can read the message (and then this will repeat over and over because this is the startup program…)
not sure why i did write instead of print however the reboot didnt seem to wipe it i assumed it was writing it again before the screen was clear due to it just repeating over and over
Edited on 15 August 2014 - 11:55 AM
natedogith1 #8
Posted 15 August 2014 - 02:17 PM

local q1
local q2
local q3
local q4
if fs.exists("disk/app") then write("Remove current disk and reboot")
os.reboot()
else
		print("Why are you applying to become staff of Oceanic Cove:")
		q1 = read()
		term.clear()
	  
		print("How old are you?:")
		q2 = read()
		term.clear()
	  
		print("do you have or can you get ts3(teamspeak)")
		q3 = read()
		term.clear()

		print("What do you think makes you more Valuable then other Applicants?:")
		q4 = read()
		term.clear()
end
local f = fs.open("disk/app", "w")
f.writeLine(q1)
f.writeLine(q2)
f.writeLine(q3)
f.writeLine(q4)
f.close()
print("Remove disk and throw under the computer thanks for your application")

ok so what im attempting to do is set it so it asks the questions (q1,q2,q3,q4) and reads the input and writes that in another program with the program being on a disk.

not sure but im getting a startup:26: attempt to index? (a nil value)
It would seem that fs.open isn't returning anything, I think this can happen if the file is read only, though I'm not sure (it might be that read-only throws an error).

Also, I personally think using term.write() instead of write() is better, but that's up to you.
There is a difference between term.write() and write(), namely in that write() handles new lines and wrapping for you. Though there is the issue that where the write is used (and I'm not sure why it's not print), the screen will be cleared by the reboot before the user can read the message (and then this will repeat over and over because this is the startup program…)
not sure why i did write instead of print however the reboot didnt seem to wipe it i assumed it was writing it again before the screen was clear due to it just repeating over and over
That could be the case, but even still that's a bad practice.
Wooki_inthetrees #9
Posted 15 August 2014 - 02:34 PM
any ideas on how i could prevent that from occouring?
theoriginalbit #10
Posted 15 August 2014 - 02:50 PM
is there actually a disk in the computer under the mount path disk?

a common mistake that people do not realise is that all folder structures must exist prior to being able to open a file, if the file cannot be opened it will simply return no value; which of course you can check for


local h = fs.open("disk/app", "w")
if not h then
  print("Could not open the file at disk/app")
else
  print("File was opened, can now write to it")
end

run this code and if anything shows false then you have a problem indicated by which is false

print("Path exists: ", fs.exists("disk"))
print("Is folder: ", fs.isDir("disk"))
print("Can write: ", not fs.isReadOnly("disk"))

print("File path exists: ", fs.exists("disk/app"))
print("Is file: ", not fs.isDir("disk/app"))
print("Can write: ", not fs.isReadOnly("disk/app"))

print("Opened file: ", fs.open("disk/app", "w") ~= nil))
Edited on 15 August 2014 - 12:52 PM
Wooki_inthetrees #11
Posted 15 August 2014 - 03:05 PM
i apoligize for my ignorance there wasnt a disk in the drive i dont know why i iddnt check that sorry :(/>
Wooki_inthetrees #12
Posted 15 August 2014 - 03:17 PM
is there a way i can have the program label the disk aswell by adding local label the label = read() and have it ask for the players ign?
its just that i dont know how to have a program label a disk i tried label set left (lab) ps lab is what i named the local label
Edited on 15 August 2014 - 01:23 PM
theoriginalbit #13
Posted 15 August 2014 - 03:20 PM
Take a look at the Disk API.
Wooki_inthetrees #14
Posted 15 August 2014 - 04:13 PM

local pullEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
local q1
local q2
local q3
local q4
local lab
if fs.exists("disk/app") then write("Remove current disk throw away and reboot (hold control R to reboot)")
os.reboot()
[b]elseif
disk.hasData("left") == false then print("Insert Disk and reboot (hold control R to reboot)")

os.reboot()[/b]
else
		print("what is your in-game name?")
		lab = read()
		term.clear()
	  
		print("Why are you applying to become staff of Oceanic Cove:")
		q1 = read()
		term.clear()
	  
		print("How old are you?:")
		q2 = read()
		term.clear()
	  
		print("do you have or can you get ts3(teamspeak)")
		q3 = read()
		term.clear()

		print("What do you think makes you more Valuable then other Applicants?:")
		q4 = read()
		term.clear()

end
local f = fs.open("disk/app", "w")
f.writeLine(q1)
f.writeLine(q2)
f.writeLine(q3)
f.writeLine(q4)
f.close()
disk.setLabel("left", (lab))
print("Remove disk and throw under the computer thanks for your application")
sleep(15)
os.pullEvent = pullEvent
os.reboot()

local pullEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
local q1
local q2
local q3
local q4
local lab
if fs.exists("disk/app") then write("Remove current disk throw away and reboot (hold control R to reboot)")
os.reboot()
else
		print("what is your in-game name?")
		lab = read()
		term.clear()
	  
		print("Why are you applying to become staff of Oceanic Cove:")
		q1 = read()
		term.clear()
	  
		print("How old are you?:")
		q2 = read()
		term.clear()
	  
		print("do you have or can you get ts3(teamspeak)")
		q3 = read()
		term.clear()

		print("What do you think makes you more Valuable then other Applicants?:")
		q4 = read()
		term.clear()
[b]disk.hasData("left") == false then print("Insert Disk and reboot (hold control R to reboot)")
os.reboot[/b]
end
local f = fs.open("disk/app", "w")
f.writeLine(q1)
f.writeLine(q2)
f.writeLine(q3)
f.writeLine(q4)
f.close()
disk.setLabel("left", (lab))
print("Remove disk and throw under the computer thanks for your application")
sleep(15)
os.pullEvent = pullEvent
os.reboot()

so these are the 2 versions of the code im working with i set the differences as far as i could tell to bold what im trying to get it to do is check for a disk to the left before trying to continue with writing on the disk so that it doesnt give a error allowing people to change the code/edit the computer in any way
Edited on 15 August 2014 - 02:15 PM
Wooki_inthetrees #15
Posted 15 August 2014 - 04:53 PM
alrighty then i figured it out :P/> i really appreciate all of you guys help!!!! :P/> heres the finished code http://pastebin.com/ZfASpc6S