Jump to content




Need help!


  • You cannot reply to this topic
11 replies to this topic

#1 Felype

  • Members
  • 43 posts
  • LocationBrazil

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 nill


Code:
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


#2 gollark8

  • Members
  • 207 posts

Posted 05 January 2014 - 01:08 PM

 Felype, on 05 January 2014 - 01:03 PM, said:

First problem:
i want to make a program that prints something but this error appears:
print:2: attempt to call nill


Code:
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


#3 Engineer

  • Members
  • 1,378 posts
  • LocationThe 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 by Engineer, 05 January 2014 - 01:12 PM.


#4 mrpoopy345

  • Members
  • 148 posts
  • LocationMy Computer

Posted 05 January 2014 - 01:10 PM

EDIT: NINJA'D.

Edited by mrpoopy345, 05 January 2014 - 01:11 PM.


#5 Moody

  • Members
  • 28 posts

Posted 05 January 2014 - 01:12 PM

 Felype, on 05 January 2014 - 01:03 PM, said:

First problem:
i want to make a program that prints something but this error appears:
print:2: attempt to call nill


Code:
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)

#6 Felype

  • Members
  • 43 posts
  • LocationBrazil

Posted 05 January 2014 - 01:15 PM

 gollark8, on 05 January 2014 - 01:08 PM, said:

 Felype, on 05 January 2014 - 01:03 PM, said:

First problem:
i want to make a program that prints something but this error appears:
print:2: attempt to call nill


Code:
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

#7 Moody

  • Members
  • 28 posts

Posted 05 January 2014 - 01:17 PM

 Felype, on 05 January 2014 - 01:15 PM, said:

 gollark8, on 05 January 2014 - 01:08 PM, said:

 Felype, on 05 January 2014 - 01:03 PM, said:

First problem:
i want to make a program that prints something but this error appears:
print:2: attempt to call nill


Code:
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 by Moody, 05 January 2014 - 01:19 PM.


#8 Felype

  • Members
  • 43 posts
  • LocationBrazil

Posted 05 January 2014 - 01:40 PM

 Moody, on 05 January 2014 - 01:12 PM, said:

 Felype, on 05 January 2014 - 01:03 PM, said:

First problem:
i want to make a program that prints something but this error appears:
print:2: attempt to call nill


Code:
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 by Felype, 05 January 2014 - 01:49 PM.


#9 Moody

  • Members
  • 28 posts

Posted 05 January 2014 - 01:54 PM

Quote

Quote

 Felype, on 05 January 2014 - 01:03 PM, said:

First problem:
i want to make a program that prints something but this error appears:
print:2: attempt to call nill


Code:
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"
?

Quote

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 )

#10 Felype

  • Members
  • 43 posts
  • LocationBrazil

Posted 05 January 2014 - 02:09 PM

 Moody, on 05 January 2014 - 01:54 PM, said:

Quote

Quote

 Felype, on 05 January 2014 - 01:03 PM, said:

First problem:
i want to make a program that prints something but this error appears:
print:2: attempt to call nill


Code:
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"
?

Quote

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?

#11 Moody

  • Members
  • 28 posts

Posted 05 January 2014 - 02:32 PM

 Felype, on 05 January 2014 - 02:09 PM, said:

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 by Moody, 05 January 2014 - 02:39 PM.


#12 Felype

  • Members
  • 43 posts
  • LocationBrazil

Posted 05 January 2014 - 02:47 PM

 Moody, on 05 January 2014 - 02:32 PM, said:

 Felype, on 05 January 2014 - 02:09 PM, said:

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users