Jump to content

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

turtle wireless utility

5 replies to this topic

#1 KnightMiner

  • Members
  • 61 posts
  • Locationattempt to index "location" (a nil value)

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".

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

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.

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.

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.
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
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.
"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 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
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"

Posted Image

Edited by KnightMiner, 29 February 2016 - 02:04 AM.

#2 Lupus590

  • Members
  • 2,027 posts
  • LocationUK

Posted 10 February 2016 - 11:23 AM

Nice, +1 for you

#3 LDDestroier

  • Members
  • 1,095 posts
  • LocationACDC Town

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.

#4 gustavowizard

  • Members
  • 94 posts

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!

nice avatar btw... LoL


  • Members
  • 292 posts

Posted 11 February 2016 - 03:44 PM

No, it works with the in-game cht.

#6 KnightMiner

  • Members
  • 61 posts
  • Locationattempt to index "location" (a nil value)

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 by KnightMiner, 29 February 2016 - 01:59 AM.

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users