Posted 07 March 2015 - 02:04 PM
Ever wished you could simply write the following into a turtle, and it would just… work?
Of even this?
You use your turtles a lot and wish to know what they are currently up to?
Just name the programs and you can know which step it currently is at.
To see just how powerful this new feature is, lets see exactly how your scripts need to be altered, using the above example!
Everything is made simple for you, just type in do and it will do any turtle command or run any program on the turtles internal memory! It works with the turtle API straight out of the box, but best of all, integrating it with your own api takes a few seconds; simply go to line 120 and add in the location of your API in quotation marks and you are done! (Ex: "rom/apis/turtle/turtle" )
Guide
To use the sub-programs( the arguments in "("s and ")"s) there must be a space before and after the parenthesis
To be able to call programs on the turtle, the name may not be a number, nor match the name of a function in the loaded API
To test out that all is up and running, use the following program, changing to your own API functions, to make a 3 * 3 platform:
Advanced guide:
Use in user created programs:
Load up your API using the method used above, then you are ready to begin using the program.
The runProgram() method is accessible when loaded as an API, its use is fairly straight forward: You can either make a list of all the arguments in the program exactly as if you had entered it into the command line, or you can pre-"compile" the code to be run, for this use case see the section on "compiling" the programs.
Once the code to be run is made into a list (a table) use the runProgram. This example assumes that the table is called "table", and the number of times to run is a variable called "timesToRun"
"Compiling" the code:
The term compiling is used fairly loosely in this case, but will save the program some time, as it doesnt require to relist subprograms, hence the use of the term compile; now that this is out of the way lets begin.
When the programs run, if they encounter a "(" it will make a list from the starting parenthesis to it's matching ending parenthesis exclusively, to then run the list the appropriate amount of times. If you are aiming to make the use of this program as efficient as possible, it is possible to save a good deal of time on this operation by pre-"compiling" the code into tables, omitting the use of "("s and ")"s
The runProgram method returns the "compiled" code once it has run, allowing for internal reuse of the pre-compiled code if it needs to be run multiple times, also allowing the user to save the code in it's "compiled" form if they so desire.
You are now a do expert!
Changelog
If there are any questions please do bring them up, I'd be glad to help out
V0.2 - PasteBin - 1dUgMiH6
Obsoleted Versions:
do forward 3 ( mineshaft forward 3 ) 5 turnLeft 2 forward 18 drop
this sample would go forward 3 blocks, then dig five mineshafts to bedrock 3 blocks apart from each other, turn around, go back to where it started and drop all it's contents in front of it at your feet.Of even this?
do set HouseBuilder forward ( set BuildUp up ( set BuildCorner ( set BuildWall placeDown forward ) 4 placeDown turnRight ) 4 ) 3 turnRight forward turnLeft ( set BuildRoof ( placeDown forward ) 4 turnRight forward turnRight ( placeDown forward ) 4 turnLeft forward turnLeft ( placeDown forward ) 4 turnLeft forward 3 turnLeft forward 5 down 3 )
to build a 5 * 5 house ahead and to the right of where the turtle currently is, then head back to where it used to be?You use your turtles a lot and wish to know what they are currently up to?
Just name the programs and you can know which step it currently is at.
To see just how powerful this new feature is, lets see exactly how your scripts need to be altered, using the above example!
do set Placement forward 3 ( set Mining mineshaft forward 3 ) 5 turnLeft 2 forward 18 drop
While this code is running, the turtle would declare that it is in the "Placement" phase while not in the inner program, and mention that it is currently mining when in the sub-program.Everything is made simple for you, just type in do and it will do any turtle command or run any program on the turtles internal memory! It works with the turtle API straight out of the box, but best of all, integrating it with your own api takes a few seconds; simply go to line 120 and add in the location of your API in quotation marks and you are done! (Ex: "rom/apis/turtle/turtle" )
Guide
Spoiler
Begin your commands with do then any lua option under the loaded API can be used.To use the sub-programs( the arguments in "("s and ")"s) there must be a space before and after the parenthesis
To be able to call programs on the turtle, the name may not be a number, nor match the name of a function in the loaded API
loadAPIs("rom/apis/turtle/turtle")
Once this is done, do is set to go; simply type do and create your movement patterns and it will execute them.To test out that all is up and running, use the following program, changing to your own API functions, to make a 3 * 3 platform:
do set Platform ( ( placeDown forward turnRight ) 4 forward ) 4
Advanced guide:
Spoiler
Use in user created programs:
Load up your API using the method used above, then you are ready to begin using the program.
The runProgram() method is accessible when loaded as an API, its use is fairly straight forward: You can either make a list of all the arguments in the program exactly as if you had entered it into the command line, or you can pre-"compile" the code to be run, for this use case see the section on "compiling" the programs.
Once the code to be run is made into a list (a table) use the runProgram. This example assumes that the table is called "table", and the number of times to run is a variable called "timesToRun"
runProgram(table, timesToRun)
"Compiling" the code:
The term compiling is used fairly loosely in this case, but will save the program some time, as it doesnt require to relist subprograms, hence the use of the term compile; now that this is out of the way lets begin.
When the programs run, if they encounter a "(" it will make a list from the starting parenthesis to it's matching ending parenthesis exclusively, to then run the list the appropriate amount of times. If you are aiming to make the use of this program as efficient as possible, it is possible to save a good deal of time on this operation by pre-"compiling" the code into tables, omitting the use of "("s and ")"s
The runProgram method returns the "compiled" code once it has run, allowing for internal reuse of the pre-compiled code if it needs to be run multiple times, also allowing the user to save the code in it's "compiled" form if they so desire.
You are now a do expert!
Changelog
Spoiler
V0.2 - Complete rewrite to be much more robust, and easier to use in user programs. Added in the "set" keyword allowing for named programs, helpful when looking for errors in scripts using this toolIf there are any questions please do bring them up, I'd be glad to help out
V0.2 - PasteBin - 1dUgMiH6
Obsoleted Versions:
Spoiler
V0.1 PasteBin: vM0qBB7REdited on 10 March 2015 - 02:22 PM