55 posts
Location
Brazil
Posted 05 January 2014 - 01:03 PM
First problem:i want to make a program that prints something but this error appears:
print:2: attempt to call nillCode:
local p = peripheral.wrap("right")
p.newPage() --forgot that
local function printToPrinter(text)
p.write(text.."/n")
end
printToPrinter(mytexthere)
Second problem:I want to make a program that formats the computer,but this error appears:
bios:339: [string "format"]:13: 'end' expected (to close 'for' at line 6)
Code:
print("Do u really want to format tottaly the computer?")
print("type Y if u really want type anything if not")
write("Really?: ")
y = read()
if y == y then
for k,v in pairs(fs.list("/")) do
if not fs.isReadOnly(v) then
fs.delete(v)
print("Sucefully formatted!")
sleep(2)
os.shutdown()
end
else
print("Cancelled formatting")
sleep(2)
os.reboot()
end
end
208 posts
Posted 05 January 2014 - 01:08 PM
First problem:i want to make a program that prints something but this error appears:
print:2: attempt to call nillCode:
local p = peripheral.wrap("right")
p.newPage() --forgot that
local function printToPrinter(text)
p.write(text.."/n")
end
printToPrinter(mytexthere)
Second problem:I want to make a program that formats the computer,but this error appears:
bios:339: [string "format"]:13: 'end' expected (to close 'for' at line 6)
Code:
print("Do u really want to format tottaly the computer?")
print("type Y if u really want type anything if not")
write("Really?: ")
y = read()
if y == y then
for k,v in pairs(fs.list("/")) do
if not fs.isReadOnly(v) then
fs.delete(v)
print("Sucefully formatted!")
sleep(2)
os.shutdown()
end
else
print("Cancelled formatting")
sleep(2)
os.reboot()
end
end
For #2 I assume you're actually missing an end.
print("Do u really want to format tottaly the computer?")
print("type Y if u really want type anything if not")
write("Really?: ")
input = read()
input = string.lower(input)
if input == y then
for k,v in pairs(fs.list("/")) do
if not fs.isReadOnly(v) then
fs.delete(v)
end
end --I THINK it goes there
print("Sucefully formatted!")
sleep(2)
os.shutdown()
end
else
print("Cancelled formatting")
sleep(2)
os.reboot()
end
1522 posts
Location
The Netherlands
Posted 05 January 2014 - 01:10 PM
http://www.computerc...ts-lua-edition/Ignore this post, in short: I have a scumbag brain
Edited on 05 January 2014 - 12:12 PM
147 posts
Location
My Computer
Posted 05 January 2014 - 01:10 PM
EDIT: NINJA'D.
Edited on 05 January 2014 - 12:11 PM
28 posts
Posted 05 January 2014 - 01:12 PM
First problem:i want to make a program that prints something but this error appears:
print:2: attempt to call nillCode:
local p = peripheral.wrap("right")
p.newPage() --forgot that
local function printToPrinter(text)
p.write(text.."/n")
end
printToPrinter(mytexthere)
Have you actually defined your variable "mytexthere" somewhere? else it does not exist and you try to print a nonexisting variable (which is nil)
55 posts
Location
Brazil
Posted 05 January 2014 - 01:15 PM
First problem:i want to make a program that prints something but this error appears:
print:2: attempt to call nillCode:
local p = peripheral.wrap("right")
p.newPage() --forgot that
local function printToPrinter(text)
p.write(text.."/n")
end
printToPrinter(mytexthere)
Second problem:I want to make a program that formats the computer,but this error appears:
bios:339: [string "format"]:13: 'end' expected (to close 'for' at line 6)
Code:
print("Do u really want to format tottaly the computer?")
print("type Y if u really want type anything if not")
write("Really?: ")
y = read()
if y == y then
for k,v in pairs(fs.list("/")) do
if not fs.isReadOnly(v) then
fs.delete(v)
print("Sucefully formatted!")
sleep(2)
os.shutdown()
end
else
print("Cancelled formatting")
sleep(2)
os.reboot()
end
end
For #2 I assume you're actually missing an end.
print("Do u really want to format tottaly the computer?")
print("type Y if u really want type anything if not")
write("Really?: ")
input = read()
input = string.lower(input)
if input == y then
for k,v in pairs(fs.list("/")) do
if not fs.isReadOnly(v) then
fs.delete(v)
end
end --I THINK it goes there
print("Sucefully formatted!")
sleep(2)
os.shutdown()
end
else
print("Cancelled formatting")
sleep(2)
os.reboot()
end
bios:339: [string "format"]:16: 'eof' expected
28 posts
Posted 05 January 2014 - 01:17 PM
First problem:i want to make a program that prints something but this error appears:
print:2: attempt to call nillCode:
local p = peripheral.wrap("right")
p.newPage() --forgot that
local function printToPrinter(text)
p.write(text.."/n")
end
printToPrinter(mytexthere)
Second problem:I want to make a program that formats the computer,but this error appears:
bios:339: [string "format"]:13: 'end' expected (to close 'for' at line 6)
Code:
print("Do u really want to format tottaly the computer?")
print("type Y if u really want type anything if not")
write("Really?: ")
y = read()
if y == y then
for k,v in pairs(fs.list("/")) do
if not fs.isReadOnly(v) then
fs.delete(v)
print("Sucefully formatted!")
sleep(2)
os.shutdown()
end
else
print("Cancelled formatting")
sleep(2)
os.reboot()
end
end
For #2 I assume you're actually missing an end.
print("Do u really want to format tottaly the computer?")
print("type Y if u really want type anything if not")
write("Really?: ")
input = read()
input = string.lower(input)
if input == y then
for k,v in pairs(fs.list("/")) do
if not fs.isReadOnly(v) then
fs.delete(v)
end
end --I THINK it goes there
print("Sucefully formatted!")
sleep(2)
os.shutdown()
end
else
print("Cancelled formatting")
sleep(2)
os.reboot()
end
bios:339: [string "format"]:16: 'eof' expected
print("Do u really want to format tottaly the computer?")
print("type Y if u really want type anything if not")
write("Really?: ")
input = read()
input = string.lower(input)
if input == y then
for k,v in pairs(fs.list("/")) do
if not fs.isReadOnly(v) then
fs.delete(v)
end --I THINK it goes there
print("Sucefully formatted!")
sleep(2)
os.shutdown()
end
else
print("Cancelled formatting")
sleep(2)
os.reboot()
end
he inserted 2 ends
Also - it would help if you actually read what the error says, it might help you detect the flaws without asking somebody else.
Edited on 05 January 2014 - 12:19 PM
55 posts
Location
Brazil
Posted 05 January 2014 - 01:40 PM
First problem:i want to make a program that prints something but this error appears:
print:2: attempt to call nillCode:
local p = peripheral.wrap("right")
p.newPage() --forgot that
local function printToPrinter(text)
p.write(text.."/n")
end
printToPrinter(mytexthere)
Have you actually defined your variable "mytexthere" somewhere? else it does not exist and you try to print a nonexisting variable (which is nil)
It printed but no text in the page.(Now printed but appears a /n)
The format program worked yay,thanks everyone!
Another question:
Its possible to make a program that edits/creates a program?
Edited on 05 January 2014 - 12:49 PM
28 posts
Posted 05 January 2014 - 01:54 PM
First problem:i want to make a program that prints something but this error appears:
print:2: attempt to call nillCode:
local p = peripheral.wrap("right")
p.newPage() --forgot that
local function printToPrinter(text)
p.write(text.."/n")
end
printToPrinter(mytexthere)
Have you actually defined your variable "mytexthere" somewhere? else it does not exist and you try to print a nonexisting variable (which is nil)
It printed but no text in the page.
What?
Have you defined your variable somewhere before in your code? Like
mytexthere = "Hello world"
?
The format program worked yay,thanks everyone!
Another question:
Its possible to make a program that edits/creates a program?
You can open a program/file and edit it with the FS API (
http://computercraft.info/wiki/Fs.open )
55 posts
Location
Brazil
Posted 05 January 2014 - 02:09 PM
First problem:i want to make a program that prints something but this error appears:
print:2: attempt to call nillCode:
local p = peripheral.wrap("right")
p.newPage() --forgot that
local function printToPrinter(text)
p.write(text.."/n")
end
printToPrinter(mytexthere)
Have you actually defined your variable "mytexthere" somewhere? else it does not exist and you try to print a nonexisting variable (which is nil)
It printed but no text in the page.
What?
Have you defined your variable somewhere before in your code? Like
mytexthere = "Hello world"
?
The format program worked yay,thanks everyone!
Another question:
Its possible to make a program that edits/creates a program?
You can open a program/file and edit it with the FS API (
http://computercraft.info/wiki/Fs.open )
Already fixed the print error.
But can you make a example of the FS API?
28 posts
Posted 05 January 2014 - 02:32 PM
Already fixed the print error.
But can you make a example of the FS API?
okay
so for example you have a file named "program" in the same directory and you want to edit the 3rd line and want to add a word to it
strT = { }
h = fs.open("program","r") -- create a READONLY-handle for the file
tmp = h.readLine() -- read the first line
while tmp ~= nil -- if it exists, it will dump every line to an entry in the table
strT((#strT)+1) = tmp
tmp = h.readLine()
end
h.close() -- close the file
strT[3] = strT[3].." print(randomStr)" -- manipulate the 3rd line
h = fs.open("program","w") -- create a WRITE handle for the file
for i=1,#strT,1 -- write everything back to the file
h.writeLine(strT[i])
end
h.close() -- close it again
adds a print to the 3rd line
be carefull, as writing to a file overwrites everything (you cant directly write to a single line)
Edited on 05 January 2014 - 01:39 PM
55 posts
Location
Brazil
Posted 05 January 2014 - 02:47 PM
Already fixed the print error.
But can you make a example of the FS API?
okay
so for example you have a file named "program" in the same directory and you want to edit the 3rd line and want to add a word to it
strT = { }
h = fs.open("program","r") -- create a READONLY-handle for the file
tmp = h.readLine() -- read the first line
while tmp ~= nil -- if it exists, it will dump every line to an entry in the table
strT((#strT)+1) = tmp
tmp = h.readLine()
end
h.close() -- close the file
strT[3] = strT[3].." print(randomStr)" -- manipulate the 3rd line
h = fs.open("program","w") -- create a WRITE handle for the file
for i=1,#strT,1 -- write everything back to the file
h.writeLine(strT[i])
end
h.close() -- close it again
adds a print to the 3rd line
be carefull, as writing to a file overwrites everything (you cant directly write to a single line)
Wow this is very complicated xD but thanks.