This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Galbi3000's profile picture

Turtle Prompt/Scripting

Started by Galbi3000, 15 March 2015 - 01:19 AM
Galbi3000 #1
Posted 15 March 2015 - 02:19 AM
Hi,

Here is my first submission of a program to this forum :)/>

Turtle is currently in version 0.10 beta and has a few missing features. I will update this page with any changes.

The purpose of this program is to provide a simpler scripting language for people new to programming to learn so they can make better use of their turtles without the hassle of learning Lua commands, APIs, etc. :)/>

Scripts are stored in the same folder (directory) as the Turtle program and have a prefix of 'turtle.' which will not need to be added in the RUN or EDIT commands or at the TurtleOS prompt as a parameter of Turtle. For example a script file named turtle.buildHouse will be run either by typing at the TurtleOS prompt 'turtle buildHouse' or in the Turtle prompt with the command 'RUN buildHouse'. This is just so you do not try to run the script as a Lua program :)/>

The pastebin code is MzzhiwNe or download direct from http://pastebin.com/MzzhiwNe


The commands it currently supports:
SpoilerFORWARD - Moves the turtle forward one block or by a number given.
Alternatives: FORWARDS, FWD, FOR, FO, FD, F

BACK - Moves the turtle back one block or by a number given.
Alternatives: BACKWARD, BACKWARDS, BK, BA, B

UP - Moves the turtle up one block or by a given number.
Alternatives: UPWARD, UPWARDS, U, RISE

DOWN - Moves the turtle down one block or by a given number.
Alternatives: DOWNWARD, DOWNWARDS, DN, DO, D, LOWER, LWR, FALL

LEFT - Turns the turtle left once or as many times specified.
Alternatives: LFT, LT, LE, L

RIGHT - Turns the turtle right once or as many times specified.
Alternatives: RT, RI, R

DIG - Makes the turtle dig. Use AHEAD (Default), FRONT, F, UP, ABOVE, U, A, TOP, T, DOWN, D, BELOW, BOTTOM, B
Alternatives: DG, DI

PLACE - Places a block from the current inventory slot. Use the same directions as DIG.
Alternatives: PL, P

DROP - Drop items in a direction (same as DIG directions) and optionally a number of items to drop or ALL for everything in the inventory.
Alternatives: DRP, DP, DR

SUCK - Sucks dropped items from a direction (same as DIG) and optionally a number of items to suck up.
Alternatives: SK, SU, S, GRAB, GR, GET, GT, GE, G

SELECT - Selects an inventory slot. Provide a slot number 1 to 16.
Alternatives: SEL, SL, SE, INVENTORY, INV, IN, I

DETECT - Detects if there is something in a direction specified (directions as with DIG). In scripting it can be used with the IF command to do conditional commands.
Alternatives: DTCT, DCT, DT, DE, SENSE, SEN

ATTACK - Attacks the space in the direction specified (again same directions as in DIG :)/> )
Alternatives: ATK, AT, A, HIT, HT, H

EQUIP - Equips a tool from the currently selected inventory slot. Specify LEFT or RIGHT for the side to equip to.
Alternatives: EQP, EQ, E, USE

REFUEL - Refuels the turtle. Without a parameter it refuels using all items in the currently selected slot. If a number is given
it will only use that many from the slot. If ALL is specified then it will go through all slots to use all available items.
Alternatives: REF, RFL, RF

FUEL - Checks the current fuel level. Can not use this in scripts yet.
Alternatives: FL, FU

REPEAT - Can only be used in scripts. Repeats the next command in the script a specified number of times.

[ - Marks the start of a block of commands in a script to be repeated together by the REPEAT command. If used without a REPEAT then it is ignored.

] - Marks the end of the block of commands. If used without a REPEAT then it is ignored.

RUN - Runs a script

EDIT - Edits/creates a script file. It calls the ComputerCraft EDIT program and automatically adds the 'turtle.' prefix to the script name. The only time you should need to supply the 'turtle.' prefix is if you are editing the script file outside of the Turtle program.
Alternative: ED

LIST - Lists the scripts available to RUN or EDIT.
Alternatives: LS, DIR, FILES, SCRIPTS

PRINT - Displays whatever is provided after the print command on the turtle's screen.
Alternatives: ECHO, WRITE, SAY, PR, EC, WR

EXIT - Returns you to the TurtleOS prompt.
Alternatives: EX, X, QUIT, QT, Q, END

Released Version Changes:
SpoilerVersion 0.13 beta:
  • Now checks if being run in a turtle! (Should have added this from the start!!)
Version 0.12 beta:
  • Added the PRINT command
  • More 'behind the scenes' code changes
Version 0.10 beta:
  • Added the DROP command
  • Changed the SUCK command to also allow specifying a number of items
  • Code changes not noticeable to the user!
Version 0.06 beta:
  • Added LIST command to list the scripts on disk.
Version 0.05 beta:
  • Added EDIT command to edit scripts.
  • Added script running support.
  • Added support for the REPEAT command in scripts.
  • Added command block marking with [ and ] for repeating more than one command.
  • Tidied some of the code for script running with regards to errors.
Version 0.01 beta (first release):
  • Created the core functionality of the program.
  • Added all the main commands with the exception of DROP.

Todo list:
SpoilerNext planned changes, these may not be in the next release but once these are done it will be out of beta:
  • Add a HELP system for the commands.
  • Add the IF command for use in scripts.
Future versions (maybe, if I decide to add them):
  • Add nested command blocks for use of IF or REPEAT inside a block.
  • Add simple variable support and checking in IF.
  • Add argument support to scripts.

Example script (for when the scripting is implemented) to dig a horizontal tunnel 40 blocks deep, 3 blocks wide and 3 blocks high:
Spoiler

REPEAT 40
[
  DIG
  FORWARD
  LEFT
  DIG
  DIG UP
  UP
  DIG
  DIG UP
  UP
  DIG
  RIGHT 2
  DIG
  DOWN
  DIG
  DOWN
  DIG
  LEFT
]
Edited on 01 April 2015 - 06:56 PM
HPWebcamAble #2
Posted 15 March 2015 - 02:31 AM
Interesting concept, looks well implemented


Didn't try so can't report any bugs for you. Just one question from glancing at the code:

Why do you remove tabs from the user input? I don't even think MC supports the tab character, I can't think of a place it can be typed
Galbi3000 #3
Posted 15 March 2015 - 02:35 AM
Interesting concept, looks well implemented


Didn't try so can't report any bugs for you. Just one question from glancing at the code:

Why do you remove tabs from the user input? I don't even think MC supports the tab character, I can't think of a place it can be typed

It is a 'just in case' scenario. As ComputerCraft programs can be edited outside of Minecraft using ordinary or programmer specific text editors (that's how I edit/create mine) then there could be a possibility of a tab getting in there for scripts. But yeah, I see your point for the prompt entry. I think I had intended the code to process lines of the script files as well but changed my mind after I wrote that bit :)/>
Galbi3000 #4
Posted 15 March 2015 - 09:22 PM
New version available. See the OP for details :)/>
Galbi3000 #5
Posted 16 March 2015 - 10:33 PM
New version 0.10 beta released. See OP for details :)/>
Galbi3000 #6
Posted 01 April 2015 - 07:44 PM
Another small update released. Version 0.12 beta. Added the PRINT command to allow scripts to display messages on the screen. See OP for full details on the command :)/>

The help system and IF command are still in the pipeline. It's just that other real world things have taken a temporary priority :wacko:/>

*EDIT*
Very minor release update to 0.13 beta. Now includes checking if running on a turtle! I know, should have added that check in the first version! It totally slipped my mine until now :D/>
Edited on 01 April 2015 - 06:58 PM
H4X0RZ #7
Posted 01 April 2015 - 08:20 PM
Looks nice!

By looking at the code, I'm not entirely sure if nested loops would work.
I mean something like this:

REPEAT 20
[
  UP
  REPEAT 5
  [
    FORWARD
  ]
]
Edited on 01 April 2015 - 07:18 PM
Galbi3000 #8
Posted 01 April 2015 - 09:05 PM
Looks nice!

By looking at the code, I'm not entirely sure if nested loops would work.
I mean something like this:

REPEAT 20
[
  UP
  FORWAR
]
Yes, currently the Lua code does not provide support for nested loops. It is a messy part of the whole program, an untidy workaround to get the looping working in an early beta form. I will need time to plan how to do it correctly in a way that would allow nesting but currently real life issues are getting in the way :angry:/>

The way nested loops would work would be something like:


REPEAT 5
[
  UP
  REPEAT 4
  [
	REPEAT 4
	[
	  FORWARD
	  PLACE DOWN
	]
	RIGHT
  ]
]

Which would (if I included nested looping support) build 4 walls of 5x5 making an open topped box. Such code could be the base for building a house.
But like I said, I would have to build in support for nested loops for such code to work :)/>

*EDIT* PS, Yes I realise the sample code above would fail to build the walls fully as it would run out of blocks before finishing. It's just a theoretical code sample not actual code that would work as is ;)/>
Edited on 01 April 2015 - 07:16 PM