Posted 29 August 2013 - 08:13 PM
Hey guys!
I've created a program that I have named "do" over at http://turtlescripts.com/file/gjdhq8.
What the program does is allow you to stack commands at the prompt in both your computers and turtles. This is similar to how you can compound commands Linux and Unix.
For instance my favorite turtle is chock full of custom programs such as my "dig" program also at turtlescripts.com that allows you to make your turtle dig in a direction for any length of blocks. And a few other programs that I've copied from M3gabuild and Miz3craft.
So using the program I can tear down a quarry plus its associated portal rather effortlessly as seen in my video at [media]http://www.youtube.com/watch?v=l8uKdPkLRhs[/media].
I now present you with my code which is amazingly simplistic and I am betting after you guys dive into it; it'll get even more awesome and optimized. Not to mention feature enriched.
Pastebin: wSWv68HL
Url: http://pastebin.com/wSWv68HL
Changes to this page: 5/31/2014 updated code block to reflect v2.0
I've created a program that I have named "do" over at http://turtlescripts.com/file/gjdhq8.
What the program does is allow you to stack commands at the prompt in both your computers and turtles. This is similar to how you can compound commands Linux and Unix.
For instance my favorite turtle is chock full of custom programs such as my "dig" program also at turtlescripts.com that allows you to make your turtle dig in a direction for any length of blocks. And a few other programs that I've copied from M3gabuild and Miz3craft.
So using the program I can tear down a quarry plus its associated portal rather effortlessly as seen in my video at [media]http://www.youtube.com/watch?v=l8uKdPkLRhs[/media].
I now present you with my code which is amazingly simplistic and I am betting after you guys dive into it; it'll get even more awesome and optimized. Not to mention feature enriched.
Spoiler
--[[
Created by Kreezxil
On 8/28/2013
Changelog:
5/31/2014 - cleaned up code, optimized explode and implode, fixed parameter dropping
pastebin: wSWv68HL
Description: Allows turtles and computers to have
command line scripting.
Usage:
do <<command>[args];[<command>[args];...]>
--]]
local debug = false
--[[
explode function by Kreezxil
cause: learned by example. yay. \o/
--]]
function explode(div,str)
if(div=='') then
return false
end
if string.sub(str,-1,-1) ~= ";" then
str = str .. ";"
end
local tmp = ""
local arr = {}
for i=1,#str do
local char = string.sub(str,i,i)
if char == div then
if tmp ~= "" then
print("Adding [" .. tmp .."] to result array")
table.insert(arr,tmp)
end
tmp = ""
else
if char ~= nil then
tmp = tmp .. char
end
end
end
return arr
end
--[[
implode function by Kreezxil
cause: learned by example. yay. \o/
--]]
function implode(div,arr)
if(div=='') then
return false
end
result = ""
for i=1,#arr do
result = result .. div .. arr[i]
end
return result
end
local args = { ... }
if #args <1 then
print ("Usage:")
print("")
print("do <<commands>[args];[<commands>[args];...]>")
return
end
if debug then
for i=1,#args do
print("Arg[" .. i .. "]: " .. args[i])
end
end
-- turn args into a string called compacted
local compacted = implode(" ",args)
if debug then
print("Args after implosion:")
print(compacted)
end
--[[
turn compacted string of args into our
array for use with shell.run
--]]
stack = explode(";" , compacted)
if debug then
print("Command Stack is: ")
for i=1,#stack do
print("CMD[" .. i .. "] " .. stack[i])
end
end
print ("Processing command stack.")
for i=1,#stack do
shell.run(stack[i])
end
Pastebin: wSWv68HL
Url: http://pastebin.com/wSWv68HL
Changes to this page: 5/31/2014 updated code block to reflect v2.0
Edited on 31 May 2014 - 03:37 PM