Posted 30 May 2014 - 05:30 PM
Hello World
I'm working on building an intro to programming curriculum with computer craft aimed at kids grades 1-3. I have a system where they don't directly deal with the shell until a later lesson, to keep them focus on coding and avoid confusion. it's also set up(in other code) for them to edit on a computer which sends the programs to the turtle over rednet. Right now i have a file menu system, when they create a new program it copies a template and opens it for editing. Everything works, except the copy function. it works once, and everything else works after you use it once. if you enter copy again i get
101:attempt to call string
i don't see and missing ..'s and it did work the first time.
I'm working on building an intro to programming curriculum with computer craft aimed at kids grades 1-3. I have a system where they don't directly deal with the shell until a later lesson, to keep them focus on coding and avoid confusion. it's also set up(in other code) for them to edit on a computer which sends the programs to the turtle over rednet. Right now i have a file menu system, when they create a new program it copies a template and opens it for editing. Everything works, except the copy function. it works once, and everything else works after you use it once. if you enter copy again i get
101:attempt to call string
i don't see and missing ..'s and it did work the first time.
function edit()
local input="42"
while true do
valid=false
while not valid do
term.clear()
term.setCursorPos(1,1)
print("Program Editor")
print("")
list = fs.list("turtle")
if #list==0 then
print("No Programs Created Yet. Hit enter.")
io.read()
return
end
print([[Enter the name of the program you'd like to edit or x to exit then hit enter.
]])
while not valid do
list = fs.list("turtle")
textutils.pagedTabulate(list)
print("")
input = tostring(io.read())
for i=1, #list do
if list[i] == input then valid = true break end
end
if not valid and input~="x" and input~="42" then
print(input.." does not exist. Please check for typos and try again or type x to exit.")
elseif input=="x" then
return
end
end
end
shell.run("fg edit turtle/"..input)
end
return
end
function copy()
local input = "42"
list = fs.list("turtle")
while true do
valid=false
while not valid do
term.clear()
term.setCursorPos(1,1)
print("Program Copier")
print("")
while not valid do
list = fs.list("turtle")
textutils.pagedTabulate(list)
print("")
input = tostring(io.read())
for i=1, #list do
if list[i] == input then valid = true break end
end
if not valid and input~="x" and input~="42" then
print(input.." does not exist. Please check for typos and try again or type x to exit.")
elseif input=="x" then
return
end
end
print("What will you name this copy of "..input.."?")
copy =tostring(io.read())
fs.copy("turtle/"..input,"turtle/"..copy)
end
print("Opening "..copy.." for editing in a new tab.")
sleep(1.6)
shell.run("fg edit turtle/"..copy)
return
end
end
function new()
term.clear()
term.setCursorPos(1,1)
print("Create New Program From Template.")
print("")
print("Enter a name for this new program. Do not use spaces.")
input = io.read()
while fs.exists("turtle/"..input) and input~="x" do
print(input.." alio.ready exists. Enter a different name or enter x to exit")
local input = io.read()
end
fs.copy("template", "turtle/"..input)
shell.run("fg edit turtle/"..input)
return
end
while true do
term.clear()
term.setCursorPos(1,1)
print("Main Menu")
print("")
print("Enter edit, copy or new to edit, copy or create a new program.")
local input = io.read()
while input ~= "edit" and input ~= "copy" and input ~= "new" and input ~= "shell" do
print(input.." is not a valid command.")
input = io.read()
end
if input == "edit" then edit()
elseif input == "copy" then copy()
elseif input == "new" then new()
elseif input == "shell" then shell.run("fg shell")
end
end