3

My question is: Is it possible to create a new function or method in turtleOS? And how?

At example I want to write a function turnArround() and I want to use it in another programm

I know how I can create a new function in Lua. I just dont know how I can write and call it in a programm in turtleOS.

Qubilai
  • 31
  • 1

3 Answers3

1

fellow computercrafter. To create such a function use the following code:

function turnAround(side) dummy = side == "right" and turtle.turnRight() or turlte.turnLeft() end

Creator
  • 151
  • 1
  • 9
0

Don't know if you still need this but, here is an answer.

First of all, it would be much easier to just write the functions and the actual code all in one file, but if you must use another file, here is the command:

shell.run(string command [, string args1, string args2, ...])

And here is the shell api list: http://computercraft.info/wiki/Shell_(API)

Pythogen
  • 591
  • 5
  • 25
-1

If i'm right, you want to make an API (a file with only functions in it which can be run from another program).

Here is a nice tutorial on how to create an API:

  1. First, create a file. The name of the file will be the API name.
  2. Write your function into the file, and save it :)
  3. In your main program, you first have to load the file with os.loadAPI, before you can use the functions in your API. Replace "path/to/myAPI" with an absolute path to the file you just created.

API file:

function turnAround()
  -- Turn around
end

Main program:

os.loadAPI( "path/to/myAPI" )
myAPI.turnAround()
RedPolygon
  • 63
  • 1
  • 9
  • For posterity, could you include the relevant parts of the link which you found useful in your answer? That way, if the link goes down, changes, etc., your answer won't be rendered useless. Many thanks. – Wai Ha Lee Apr 09 '16 at 11:02
  • Sorry, forgot to do that. Fixed now – RedPolygon Apr 09 '16 at 15:41