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

Improved Turtle API (HELP)

Started by Astrophylite, 22 July 2015 - 11:13 AM
Astrophylite #1
Posted 22 July 2015 - 01:13 PM
Hi,

I am currently in the making of an Improved Turtle API. I am currently stuck on "turtle.place()" because the default Turtle API allows you to engrave text on a sign. I have got it working to place the sign, but, I cannot make it put the text on the sign.

Any help will be appreciated,
ZiR

WARNING: Be prepared for a VERY long code when opening this spoiler…
The place function is at the very bottom!
Spoiler

local oldTurtle = turtle
function turnRight( int )
  int = int or 1
  repeat
	oldTurtle.turnRight()
	int = int - 1
  until int == 0
end
function turnLeft( int )
  int = int or 1
  repeat
	oldTurtle.turnLeft()
	int = int - 1
  until int == 0
end
function forward( int )
  int = int or 1
  repeat
	oldTurtle.forward()
	int = int -1
  until int == 0
end
function back( int )
  int = int or 1
  repeat
	if oldTurtle.back() then
	  oldTurtle.back()
	  int = int - 1
	else
	  error( "Movement Obstructed while performing command: back", 0 )
	end
  until int == 0
end
function up( int )
  int = int or 1
  repeat
	if oldTurtle.up() then
	  oldTurtle.up()
	  int = int - 1
	else
	  error( "Movement Obstructed whilst performing command: up" , 0 )
	end
  until int == 0
end
function down( int )
  int = int or 1
  repeat
	if oldTurtle.down() then
	  oldTurtle.down()
	  int = int - 1
	else
	  error( "Movement Obstructed whilst performing command: down" , 0 )
	end
  until int == 0
end
function attack( int )
  int = int or 1
  repeat
	oldTurtle.attack( int )
	int = int - 1
  until int == 0
end
function attackUp( int )
  int = int or 1
  repeat
	oldTurtle.attackUp()
	int = int - 1
  until int == 0
end
function attackDown( int )
  int = int - 1
  repeat
	oldTurtle.attackDown()
	int = int - 1
  until int == 0
end
function select( int )
  if int > 16 then
	error( "Cannot select that slot!" , 0 )
  elseif int < 1 then
	error( "Cannot select that slot!" , 0 )
  elseif int > 0 and int < 17 then
	oldTurtle.select( int )
  end
end
function refuel( int )
  int = int or 1
  repeat
	for i = 1,16 do
	  turtle.select(i)
	  if oldTurtle.refuel(0) then
		turtle.refuel( int )
	  end
	end
	int = int - 1
  until int == 0
end
function dig( int )
  int = int or 1
  repeat
	oldTurtle.dig()
	int = int - 1
  until int == 0
end
function digUp( int )
  int = int or 1
  repeat
	oldTurtle.digUp()
	int = int - 1
  until int == 0
end
function digDown( int )
  int = int or 1
  repeat
	oldTurtle.digDown()
	int = int - 1
  until int == 0
end
function suck()
  oldTurtle.suck()
end
function suckUp()
  oldTurtle.suckUp()
end
function suckDown()
  oldTurtle.suckDown()
end
function equip( slot , side )
  if side == "right" then
	local currentSlot = oldTurtle.getSelectedSlot()
	turtle.select( slot )
	oldTurtle.equipRight( slot )
	turtle.select( currentSlot )
  elseif side == "left" then
	local currentSlot = oldTurtle.getSelectedSlot()
	turtle.select( slot )
	oldTurtle.equipLeft()
	turtle.select( currentSlot )
  elseif not slot then
	error( "Where can I find said tool ?")
  elseif not side then
	error( "I am not a psychic, I do not know what side you want me to equip this tool on." , 0 )
  else
	error( "Side not found" , 0 )
  end
end
function craft( quantity )
  oldTurtle.craft( quantity )
end
function getSelectedSlot()
  oldTurtle.getSelectedSlot()
end
function getItemCount( slot )
  if not slot then
	oldTurtle.getItemCount( oldTurtle.getSelectedSlot( ) )
  else
	oldTurtle.getItemCount( slot )
  end
end
function getItemSpace( slot )
  if not slot then
	oldTurtle.getItemSpace( oldTurtle.getSelectedSlot( ) )
  else
	oldTurtle.getItemSpace( slot )
  end
end
function getItemDetail( slot )
  if not slot then
	oldTurtle.getItemDetail( oldTurtle.getSelectedSlot( ) )
  else
	oldTurtle.getItemDetail( slot )
  end
end
function place( signText )
  if signText then
  
  end
  oldTurtle.place()
end
function placeUp()
end
function placeDown()
end
Edited on 22 July 2015 - 11:14 AM
MKlegoman357 #2
Posted 22 July 2015 - 01:26 PM
You simply have to pass the 'signText' variable to the 'oldTurtle.place' function.
Edited on 22 July 2015 - 11:26 AM
Astrophylite #3
Posted 22 July 2015 - 01:28 PM
Oh wow… I have done that for everything else but this one! Thanks for your quick response.

ZiR
MKlegoman357 #4
Posted 22 July 2015 - 01:28 PM
Instead of a repeat loop you should use a for loop, which is specifically made for what you want:


for i = 1, 10 do --# repeat the loop 10 times
  print(i)
end

--# prints:
1
2
3
4
5
6
7
8
9
10
Edited on 22 July 2015 - 11:29 AM
Astrophylite #5
Posted 23 July 2015 - 01:16 PM
Sorry, I didn't see your reply ^_^/>.
For using the for loop, would I just do:


for i = 1,int do
  turtle.forward(i)
end
MKlegoman357 #6
Posted 23 July 2015 - 01:19 PM
Yes, but you don't need to pass the 'i' variable to turtle.forward(), because it doesn't take arguments.