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

[1.47][MiscPeripherals] Sign Commands! Beta V1.0

Started by Shnupbups, 05 December 2012 - 07:38 PM
Shnupbups #1
Posted 05 December 2012 - 08:38 PM
Turtle Sign Commands by Shnupbups100

Turtle Sign Commands is a program that utilises MiscPeripherals' Reading Turtle. It allows for turtle command to be given via signs. There are a total of 12 commands at the moment, but I will add more if you request one and/or I think of another useful one. Commands include:


Left -- Turns left and goes a block forward. #
Right -- Turns right and goes a block forward. #
Break -- Breaks the sign and the block behind it, then places a Stop sign. # %
Stop -- Stops the program.
Forward -- Breaks the sign and goes forward.
Back -- Goes backward.
Up -- Goes upward.
Down -- Goes downward.
Dance -- Initiates the fun-to-watch 'dance' program.
Craft -- Crafts something with the current blocks. NOTE: WILL NOT WORK DUE TO THERE NOT BEING CRAFTY READING TURTLES.
Place -- Places a block. *

# -- Will work on. (Mostly adding arguments)
% -- Requires a Mining Reading Turtle
* -- Uses arguments


Arguments
​There is also an arguments system for adding extra points, on separate lines of the sign. Currently the only command to use them is Place, but I will add them to Break, Left and Right later on. Currently, this is how the Place arguments work:

Place
[Slot]
[Text (If sign)]
[Direction (Left, right, up or down. Leave blank for front. Back currently does not work.)]


Download
You can download this from pastebin here, or you can download from your turtle (with HTTP enabled) with:
pastebin get fkrv7r4V signCmd


Spoiler
Shhhhh! Secret image for my upcoming RCTurtle!
Edited on 15 February 2016 - 12:42 AM
Shnupbups #2
Posted 06 December 2012 - 10:12 AM
Anybody? I want feedback before I update it. :(/>
Ulthean #3
Posted 07 December 2012 - 03:16 AM
I haven't tested the program, since I only have the basic turtles, so I can't tell you how/if it works.
I just looked at the source code and have the following suggestions:
  1. For string recognition you can use string.lower(aString) which turns a string in all lowercase letters
  2. if string.lower(text1) == "right" then
  3. I suggest adding parameters to all the movement commands, like I did in my [pastebin] ExtendedAPI
  4. (copy/paste this code at the beginning of your programs and enjoy)
  5. Doing the previous you can write functions much more compact:
  6. For example, suppose a sign says :
--------
MOVE
LEFT
10
--------

[indent=1](meaning, turn left, move 10 blocks forward and turn right again (you can change this ofc))[/indent]
[indent=1]The code for this function, and more (using the extended API) would be:[/indent]
if string.lower(text1) == "move" then
  move(stringToDirection(text2), tonumber(text3)
elseif string.lower(text1) == "dig" then
  dig(stringToDirection(text2))
elseif string.lower(text1) == "digandmove" then
  digAndMove(stringToDirection(text2), tonumber(text3))
end

[indent=1]where stringToDirection would be a function saying (the variables 'up', 'down' etc get declared in the extended API):[/indent]


function stringToDirection(aString)
  lowercaseString=string.lower(aString)
  if lowercaseString == "up" then
	return up
  elseif lowercaseString == "down" then
	return down
  elseif lowercaseString == "left" then
	return left
  elseif lowercaseString == "right" then
	return right
  elseif lowercaseString == "back" then
	return back
  else
	return forward
  end
end
Shnupbups #4
Posted 07 December 2012 - 06:41 PM
SNIP
Some of that stuff you mentioned I was already thinking of adding, but some wasn't. Thanks for the ideas and expect some if not all in the next version!
ScruffyRules #5
Posted 08 December 2012 - 01:55 AM
shouldn't this go in the Peripherals and Turtle Upgrades?
Shnupbups #6
Posted 09 December 2012 - 03:00 PM
shouldn't this go in the Peripherals and Turtle Upgrades?
No, it isn't a peripheral or turtle upgrade, it is a program that uses a turtle upgrade.
Shnupbups #7
Posted 12 December 2012 - 10:18 AM
What to expect in version Beta 2.0:
~A Move function replacing Left, Right, Up, Down, Forward and Back | Has arguments
~A Turn function | Has arguments
~Break using arguments
~All code rewritten so all commands are functions that can be used in your other programs too! (May change to local later) As well as using string.lower for simplicity of reading strings.
~An Easter Egg (or two…)
And more!
Ulthean #8
Posted 12 December 2012 - 10:57 AM
What to expect in version Beta 2.0:
~A Move function replacing Left, Right, Up, Down, Forward and Back | Has arguments
~A Turn function | Has arguments
~Break using arguments
~All code rewritten so all commands are functions that can be used in your other programs too! (May change to local later) As well as using string.lower for simplicity of reading strings.
~An Easter Egg (or two…)
And more!

Keep up the good work!
Shnupbups #9
Posted 12 December 2012 - 09:49 PM
Keep up the good work!
Will do, sir!
AndreWalia #10
Posted 01 January 2013 - 12:56 PM
Keep up the good work!
Will do, sir!
CHANGE YOUR SIGNATURE
steel_toed_boot #11
Posted 01 January 2013 - 08:04 PM
instead of using multiple if cases of the name such as "BREAK" or "Break, you can convert the string to all lowercase and then read from it.

I.E.

if string.lower(text1) == "left" then
--Code goes here
end

I think that will cut away a bulk of your code. :)/>