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

Voice: a twist on the classic turtle remote using a chatbox

Started by KnightMiner, 09 February 2016 - 11:01 PM
KnightMiner #1
Posted 10 February 2016 - 12:01 AM
Ever had the issue where you are writing a bunch of temporary programs just to string turtle functions together? And then if one of those functions goes wrong, now you have to retrieve your turtle. This is especially annoying in a skyblock map, as you now have to bridge out to the turtle and risk your life.

Well, I have the solution to your problem, even if you did not have one, and its called "voice".

Installing
In order to run voice, you must have one of a MoarPeripherals chatbox, a Peripherals++ chatbox, or a wireless modem on the turtle's right. After that, install voice version 1.1 using the following command in the shell:

pastebin get r32RjcK0 voice


Usage
The program takes two parameters when starting: the username of the player controlling the turtle (or the ID of the controlling computer if using a modem), and an optional boolean called "mute". "mute" determines how the turtle should output function results, with "true" sending no results, and "false" sending all results. If the parameter is set to anything else or unset, then only the results of functions which just return data (such as turtle.inspect()) will return. The program will also take additional data from the file voice.cfg if present.

Upon running the program, the turtle interface will no longer take commands from the shell, though pressing the "end" key will exit the program to return to the shell.

Chatbox
If the turtle is equipped with a chatbox, you can control it using chatbox commands, which is done by preceding a chat message with "##" (for MoarPeripherals) or "\" (for Peripherals++). The chatbox command contains a list of commands which the turtle will call, and it will output the result using a private message from the chatbox. Only the user whose name was stated in the startup can control it.

Modem
If you are using a modem, you can control the modem using rednet messages with a protocol of "voice-command", and it will send responses back via direct message with the protocol "voice-messages", though the controlling computer's ID must match the ID stated on the turtle's startup. The easiest way to control it is by installing the program command using the following command:

pastebin get FcTRbVds command

The program has an optional parameter which if set will send a single command then exit. Otherwise, the program will open its main loop. The program also will take additional data from a Lua table in the file command.cfg if present.

The program has the following commands available:
  • link: links a turtle to send messages to. This can either be a ID number or a name from the config file. If no value is given, it disables the link, allowing you to control any turtle again
  • exit: quits the program
  • <id> <command>: runs the provided command on the turtle with the ID of "id" (or the name "id" from the config file) If the program is currently linked to a turtle, the ID must be left out.
Commands
A valid command for voice consists of multiple "functions" separated by spaces. Functions are simply the name of a function from any of the following APIs:As an example, to call turtle.dig(), you would type "dig". The following commands from those peripherals are blacklisted:If for some reason a command exists in multiple APIs, the top most one from the list is chosen (this should only happen with peripheral commands, and can be worked around using call). In addition, the following functions that are not from one of these APIs can be called:
  • mute: changes the settings for mute, as described above
    • true: causes everything to be muted
    • false: causes nothing to be muted
    • anything else: default of muting all functions that do more than return a result
  • unmute: shorthand for mute(false)
  • sleep: native Lua sleep function, sleeps for the given number of seconds
  • equip: runs turtle.equipLeft() and reloads the left peripheral
  • script: runs the specified turtle script, see "Scripts" below
  • program: runs the specified program with the specified parameters
  • say: says the provided text as the turtle. Not available if controlling the turtle using a modem
Parameters
In addition to the function name, functions can also take parameters using two brackets and separating parameters using commas, like normal Lua. For example to call turtle.transferTo(4, 10), you would type "transferTo(4,20)". Quotation marks are not needed for string parameters, rather parameters are automatically converted to a Boolean or number if possible, and will otherwise will act as a string. Strings also support the following characters escapes (ones used by the command syntax):
  • "-": replaced with a space
  • "%-": literal "-"
  • "%P": plus sign
  • "%C": comma
  • "%L": left bracket
  • "%R": right bracket
  • "%N": colon
  • "%T": "true", used for passing "true" alone as a string
  • "%F": "false", used for passing "false" alone as a string
  • "%%" or "%X": literal "%", escaping essentially.
Loops
"But what if I want to loop a single function?" Easy, simply add a colon after it, then the number of times to loop it. For example, typing "forward:5" will run turtle.forward() five times. You can also loop multiple functions by separating them using plus signs. For example, typing "forward+sleep(1)+digDown:5" will run turtle.forward(), wait a second, then run turtle.digDown().

Scripts
Scripts are files with the extension of ".tz" in the script directory (the folder "scripts" by default) that can be used as a convenient way to run a list of commands, or to loop through commands that also loop. While being more limited than programs, they are easier to write and can even be written from a command sent to the turtle (see "Inline commands" below).

The format for a script is identical to that of a command, except any form of whitespace is accepted between functions. There currently is no way to add comments to scripts, as they are meant to be written from the command line, though I may add something in the future.

Inline commands
If a command begins with one of certain keywords, it will be run as an inline command. Note that the keyword must exactly match for it to run the command, so while "script" is an inline command, "script()" is treated as a function. Unlike functions, inline commands cannot be run in a script (for obvious reasons)

The following inline commands are available:
  • script <name> [data]: saves a script with the provided name to the turtle. If "data" is unset, it will list the contents of the script.
  • delete <name>: deletes the script with the specified name
Examples
The following commands are both run using a MoarPeripherals chatbox.


##forward turnRight forward:2 equip click turnLeft:2 forward:2 turnLeft forward
Will turn the turtle to the right, move it forward two blocks, equip the tool in the selected slot, click using the claw from KnightPeripherals, turn left twice, move forward twice, and turn left. Click here to see a gif of it in action.


##script doStuff forward turnRight forward:2 equip click turnLeft:2 forward:2 turnLeft forward
Will save the above actions as a script called "doStuff.tz"

Picture
Edited on 29 February 2016 - 01:04 AM
Lupus590 #2
Posted 10 February 2016 - 11:23 AM
Nice, +1 for you
LDDestroier #3
Posted 10 February 2016 - 12:13 PM
Ohhh, that's a cool idea! This sounds very helpful if I lose my turtle in someone else's claim. I have yet to try it myself, but it sounds pretty dang nice.
gustavowizard #4
Posted 11 February 2016 - 03:20 PM
man this is really something…

1)But how this work i mean, does the program detect different words you speak on a microfone? so i could say 'dig' on the microphone and make my turtle dig?

2) does this work on regular computers too or onny Turltles? could i do a program to make nuclear missiles (from ICBM mod for example) to launch on my voice? :o/>


i did this space station with some CC programs of my own creation, like the oxygen detector/display, we should do some project anytime, plz let me know!
https://www.youtube.com/watch?v=asBnOVruTWQ

nice avatar btw… LoL
FUNCTION MAN! #5
Posted 11 February 2016 - 03:44 PM
No, it works with the in-game cht.
KnightMiner #6
Posted 29 February 2016 - 01:51 AM
I just released a the major update called 1.1 to the program, adding quite a few new features:
  • Turtles can now read lists of commands from a file using the function "script()", or run lua programs using "program()"
    • The main differences between scripts and programs are that scripts can be written from the command line and are easier to write, but are a lot more limited.
  • Turtles can no longer directly access the chatbox on the right, but they can use the new command "say()" to use the say command.
  • The program now supports using a modem instead of a chatbox, in which case the partner program command is the easiest way to control the turtle.
    • The program can either be run as a standalone to use on a pocket computer for a remote, or as a single command to add to an existing chatbox system (to control multiple turtles with a single chatbox)
  • The program now supports a config file to change the blacklisted functions, unmuted functions, plus it can blacklist programs and change the script location
  • Fixed some bugs
Edited on 29 February 2016 - 12:59 AM