Posted 07 August 2015 - 02:05 AM
I was wondering if anyone knew the language that the APIs are written in so I can start writing my own. It seems different than Lua - like a much lower-level code.
I just have some functions I'd like to integrate into the OS so that I can run something like|
"fwd 10" or "fwd * "
straight from the console to get the result,
num = read()
for i=1, read do
turtle.forward()
end
That way I can control the turtle from the command line with little work. It makes my code more concise and faster to type while allowing me to control the turtles without scripts.
For example, an API program that would advance the turtle forward until it hit a wall, or advance it as far as you'd like:
(can be used in both command line and a program)
———————————-
function fwd(num)
if num >=1 then
for i = 1, num do
turtle.forward()
end
else
while not turtle.detect() do
turtle.forward()
end
end
end
–[[omitting input checks for the purpose of clarity]]
input = read()
fwd(input)\
———————————–
then, at the command line, I can type 'fwd()' to move the turtle as far forward as possible, or 'fwd(5)' to advance it 5 blocks.
I have a long list of function like this that I made for cleaner code such as,
bck()
fwd()
rite
left
spin
lstrafe
rstrafe
fly
fall
clr (clear)
scan (enter a block)
crawl (strafes along the wall and scans)
return(x,y) – input whatever block counters you define at the beginning, and it returns to the start
I just like to reuse pieces of code like these so I can focus more time on engineering and less time on actual typing.
I'm hoping to implement these functions and more into a higher level turtle API for personal use, although I'd be thrilled to share it on the forums if people show an interest.
And, no, I don't want to use "import" all the time. I'd like to create a resource pack that plops it directly in the main APIs so that every function is accessible all of the time.
Obviously, running fwd(5) from command line would look like : fwd 5, but that's nothing copy and paste can't fix.
I just have some functions I'd like to integrate into the OS so that I can run something like|
"fwd 10" or "fwd * "
straight from the console to get the result,
num = read()
for i=1, read do
turtle.forward()
end
That way I can control the turtle from the command line with little work. It makes my code more concise and faster to type while allowing me to control the turtles without scripts.
For example, an API program that would advance the turtle forward until it hit a wall, or advance it as far as you'd like:
(can be used in both command line and a program)
———————————-
function fwd(num)
if num >=1 then
for i = 1, num do
turtle.forward()
end
else
while not turtle.detect() do
turtle.forward()
end
end
end
–[[omitting input checks for the purpose of clarity]]
input = read()
fwd(input)\
———————————–
then, at the command line, I can type 'fwd()' to move the turtle as far forward as possible, or 'fwd(5)' to advance it 5 blocks.
I have a long list of function like this that I made for cleaner code such as,
bck()
fwd()
rite
left
spin
lstrafe
rstrafe
fly
fall
clr (clear)
scan (enter a block)
crawl (strafes along the wall and scans)
return(x,y) – input whatever block counters you define at the beginning, and it returns to the start
I just like to reuse pieces of code like these so I can focus more time on engineering and less time on actual typing.
I'm hoping to implement these functions and more into a higher level turtle API for personal use, although I'd be thrilled to share it on the forums if people show an interest.
And, no, I don't want to use "import" all the time. I'd like to create a resource pack that plops it directly in the main APIs so that every function is accessible all of the time.
Obviously, running fwd(5) from command line would look like : fwd 5, but that's nothing copy and paste can't fix.