36 posts
Posted 16 January 2013 - 05:48 PM
Sales Pitch: Normally you input code and then the turtle does what you say in the code. A Reverse Engineering Turtle would record the movements and actions that the turtle makes, then write them into a file. You could then transfer that file like any other program, run it, and the recorded behaviour would be played back.
Example of Wished Suggestion:
Place RE Turtle. Give it fuel, like a normal turtle. Then type "Start Recording".
"Enter Recording Name, then press any key." will then be printed.
The RE turtle will then wait for you to input a name such as "CastleBuilder".
You press any key you please.
"Recording Started, Enter "Stop Recording" to halt." will then be printed.
You can then give it normal inputs such as "turtle.forward" or "turtle.dig()".
It will perform the entered lines, as well as record them in a file, which can be played back, as a normal program.
Additional Notes: Entering "Stop Recording", "Resume Recording", or "Pause Recording" will not cause them to be recorded. Entering "Pause Recording" will allow you to do things like write for loops without the recording process throwing errors. Guess what "Resume Recording" does.
7508 posts
Location
Australia
Posted 16 January 2013 - 05:55 PM
this section is not for coding suggestions… it is for mod suggestions… this is probably better suited to general…
1619 posts
Posted 16 January 2013 - 06:44 PM
A quick tip to point you in the right direction.
handle = fs.open("log", "a")
local oldDig = turtle.dig
function turtle.dig()
handle.writeLine("Mined a block")
oldDig()
end
Etc, etc for all of the functions.
1111 posts
Location
Portland OR
Posted 16 January 2013 - 06:45 PM
So you want a turtle that's sole function is a editor?
Seems to be a little much to me, I mean who wants to craft a special turtle so they can create programs for normal turtles? Isn't that kind of a waste of resources? I don't really see the use for this. With a little work you could probably just write a program that does this, no need for a new turtle type to be added.
In the spirit of the mod, If its really needed make it yourself or as TheOriginalBIT suggest, post in the general forums for help. The Dev's are more then likely not going to do stuff like this for you.
392 posts
Location
Christchurch, New Zealand
Posted 16 January 2013 - 08:33 PM
You do realize that you're proposing making a turtle that takes computer commands, and records them in your own special format, so that you can play them back?
And your method of doing this was with turtle.forward() etc?
Why not just write the commands in to a program and run it?
36 posts
Posted 16 January 2013 - 09:52 PM
NVM. My brain thought this was a good idea, a couple hours ago. Tomorrow I will look into coding this myself. I was just lazy after finals, happens to all of us.
871 posts
Posted 16 January 2013 - 10:52 PM
here ya' go.
local tArgs={...}
local filename=tArgs[1]
if filename==nil then
write("enter filename >")
filename=read()
end
if fs.exists(filename) then
write("file already exists!\nOverwrite? (y/n) >")
local input=read()
if input:lower()=="y" then
fs.delete(filename)
else
print("canceled.")
return
end
end
local file=fs.open(tArgs[1],"w")
if file==nil then
print("Error creating file with name '"..filename.."'!")
return
end
print("press enter on a blank line to end recording")
local line=""
while true do
write("luar> ")
local input=read()
line=line..input
if line=="" then
break
end
if line:match("^.*\\$") then
line=line:gsub("\\$","\n")
else
local func=loadstring(line)
local ok, res=pcall(func)
if ok then
file.write(line.."\n")
if res then
print("result:"..res)
end
else
print(res)
end
line=""
end
end
file.close()
print("program saved.")
pastebin get hkwyPtmW luar
It only saves lines that are valid. Basically it's like a version of the lua program that saves each non-error-generating line to a program.
:edit: This isn't nearly as bad an idea as it might initially seem, actually. I mean, there's no reason for it to be a kind of turtle, but the basic concept of recording programs from an interactive interpreter, not the worst idea ever.
:edit2: updated version, added a prompt for filename if it wasn't given as a command-line parameter, and added the ability to end a line with "\" to allow entering multiple lines at once, example:
Spoiler
>luar foo
luar> for i=1,10\
luar> print(i)\
luar> end
1
2
3
4
5
6
7
8
9
10
luar>