22 posts
Posted 23 April 2013 - 07:16 AM
I've tried different things but nothing worked. How do I make a program create another program?
Like:
fs.open("test", w)
code to write the program
fs.close
8543 posts
Posted 23 April 2013 - 07:18 AM
local handle = io.open("outfile", "w")
if handle then
handle:write([[
print("Hello, World!")
]])
handle:close()
end
537 posts
Location
Copenhagen, Denmark
Posted 23 April 2013 - 07:19 AM
EDIT: Damn ninjas.
You can use this simple piece of code:
local f = io.open("test", "w")
f:write([[
-- program code here
print("Hello from test!")
]])
f:close()
22 posts
Posted 23 April 2013 - 07:21 AM
Could you also put comments in the code so it is easier to understand?
EDIT: nvm, I figured it out. Thanks for the quick help
2088 posts
Location
South Africa
Posted 23 April 2013 - 07:23 AM
Yeah
local handle = io.open("outfile", "w")
if handle then
handle:write(
[[
-- Declare a function
local function foo( s )
print( s )
end
foo( "Hello!" )
]])
handle:close()
end
22 posts
Posted 23 April 2013 - 07:31 AM
local f = fs.open("startup", w)
f:write([[
print"Starting...."
sleep(1)
]])
f:close()
With this code I get:
test:1: Expected string, string
537 posts
Location
Copenhagen, Denmark
Posted 23 April 2013 - 07:32 AM
Put quotes around w.
22 posts
Posted 23 April 2013 - 07:37 AM
Somehow the program/file it creates is completely empty.
After some testing I found out that it doesn't do anything to the file.
2088 posts
Location
South Africa
Posted 23 April 2013 - 07:49 AM
Hmmm…if your full code is the above with just the "w" replacement. It really should work…
Have you tried restarting the PC? Lol typical IT solution. Might you have edited io somehow.
Try fs?
local f = fs.open("startup","w")
w.write([[print"Starting...."
sleep(1)]]
)
w.close()
Really the same thing…
Have you changed any ComputerCraft files?
22 posts
Posted 23 April 2013 - 07:51 AM
And by restarting it suddenly worked.
HOW!?
2088 posts
Location
South Africa
Posted 23 April 2013 - 08:06 AM
Haha. You probably overwrote something sometime…