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

storing code in a file

Started by hugeblank, 29 November 2015 - 04:57 AM
hugeblank #1
Posted 29 November 2015 - 05:57 AM
You probably get this question a million times, but how does one store lines of code in a file?

I have this:

file.writeLine(for I, side in ipairs(rs.getsides()) do)

and it gives me an error. I already have a line above that that opens the file, so it's not that.
valithor #2
Posted 29 November 2015 - 06:03 AM
Put quotes around what you are trying to write to the file:


file.writeLine("for I, side in ipairs(rs.getsides()) do")

Also you might have already done this, but don't forgot to close the file. :P/>
hugeblank #3
Posted 29 November 2015 - 06:20 AM
I did. Thank you! One question,

1. What if you have something like this:

file.writeLine("if peripheral.get Type == "modem" then")

Wouldn't it turn "modem" into a variable?
Bomb Bloke #4
Posted 29 November 2015 - 07:08 AM
Using the \ escape character to specify that we want certain quotes to be part of the string, we can do this:

file.writeLine("if peripheral.get Type == \"modem\" then")