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

Turtle Coding: Help?!

Started by hopsmax101, 16 February 2013 - 01:20 PM
hopsmax101 #1
Posted 16 February 2013 - 02:20 PM
Hi I was watching a let's play of feed the beast and the guy (Guude) was using turtles and computercraft. He made a script and posted it on a website that he made (ejectdicks.com). the script i am talking about



-- Variables
turtle.select(1)
local tArgs = { ... }
local togo = tonumber(tArgs[1])
togo = togo or 1
print("Going Boss!")

-- Functions
function tfuel(amount)
if turtle.getFuelLevel() < 5 then
  turtle.select(16)
  turtle.refuel(amount)
  turtle.select(1)
end
end


function turnaround()
  turtle.turnRight()
  turtle.turnRight()
end

function uandd()
  if turtle.detectUp() then
   turtle.digUp()
  end
  if turtle.detectDown() then
   turtle.digDown()
  end
end

-- Starting Out
for i = 1, togo do
  tfuel(1)
  if turtle.detect() then
   repeat
	turtle.dig()
	sleep(0.25)
   until turtle.detect() == false
   turtle.forward()
   uandd()
  else
   turtle.forward()
   uandd()
  end
  if togo >= 10 then
   if (i % 10 == 0) then
	turtle.placeDown()
   end
  end
end

--Lets assume that worked and he made it
turnaround()
for r = 1, togo do
tfuel(1)
turtle.forward()
end
--

I have input the script into my own game and every time I start up the script i get "mine:18: attempt to call nil" it seems to do this once it gets to line 31. in other words it mines forward, moves forward, digs up down and then says "mine:18: attempt to call nil"
help if you can!
-Max
Edited by
Lyqyd #2
Posted 16 February 2013 - 06:14 PM
Split into new topic.
ChunLing #3
Posted 16 February 2013 - 06:20 PM
Open your program in edit, navigate to line 18, and post that exact line, exactly as it appears in your turtle rather than as it appears on Guude's website.
hopsmax101 #4
Posted 17 February 2013 - 04:54 PM
Open your program in edit, navigate to line 18, and post that exact line, exactly as it appears in your turtle rather than as it appears on Guude's website.
if i understood you right then it said "bios:338: [string "mine]:18: '<name>' expected" when i put the code in line 18
LBPHacker #5
Posted 17 February 2013 - 10:39 PM
Open your program in edit, navigate to line 18, and post that exact line, exactly as it appears in your turtle rather than as it appears on Guude's website.
if i understood you right then it said "bios:338: [string "mine]:18: '<name>' expected" when i put the code in line 18

Nope. Post the 18th line of the code here.
hopsmax101 #6
Posted 18 February 2013 - 06:57 AM
ok call me slow but I'm still not getting it.
The code shouldn't read
Starting Out
for i = 1, togo do
tfuel(1)
if turtle.detect() then
repeat
But rather…?
(again sorry i know 0.000002 about code)
Shrooblord #7
Posted 18 February 2013 - 09:38 AM
What LBPHacker means is that you posted the code that Guude used, whereas you are asking us to help you solve code that you used yourself. Did you alter anything in the code? Is it an exact replica of Guude's code (i.e. did you copy-paste it over)? If not, and you did indeed modify it, then you should post the code you used as opposed to posting the original code, which should be fine as Guude used it in working condition (I assume).

So post your own code so we can look at what the 18th line looks like in your code, so we can help you.
;)/>
hopsmax101 #8
Posted 18 February 2013 - 08:32 PM
What LBPHacker means is that you posted the code that Guude used, whereas you are asking us to help you solve code that you used yourself. Did you alter anything in the code? Is it an exact replica of Guude's code (i.e. did you copy-paste it over)? If not, and you did indeed modify it, then you should post the code you used as opposed to posting the original code, which should be fine as Guude used it in working condition (I assume).

So post your own code so we can look at what the 18th line looks like in your code, so we can help you.

;)/>
ooooohhh k thank you ;)/>
got it (i didn't intentionally edit anything, though i may have mis-copied something as i did copy it by hand but)
right now it says

"function turnaround()
turtle.turnRight()
turtle.turnRight()
end

function uandd()
if turtle.detectUp() then
turtle.digUp()
end "…etc.
and on line 18 it did say tutle.turnright() so im sure that was the problem but now it prints going boss, turns 2 mines forward (my left or right), up down, turn 2 and then it just stops :P/>
thanks for the help so far ^_^/>
ChunLing #9
Posted 19 February 2013 - 01:01 AM
Sorry, didn't quite understand your description. It now "turns 2 mines forward" is a little ambiguous. Does this behavior start after what it previously did, or does it act differently right from the start?

Also, are you using the command line parameter to control how large a mine this should make: as in "mine 10"? Or are you just running it without a parameter, like, "mine"? If you run it without a mine size parameter then it defaults to 1 and the mine is going to be pretty small (it might match the behavior you describe, if I'm guessing at your meaning correctly).
hopsmax101 #10
Posted 19 February 2013 - 07:08 AM
Thank you guys! i think my only problem was that i put turtle.turnright :P/> silly mistake
i thought it was still broken but i just didn't have fuel for him in the right spot
he works now :)/>
Shrooblord #11
Posted 20 February 2013 - 03:29 AM
You could add a line of code to check for fuel. Say you always have Coal in a specific slot, for example, then you could do something like this:

(The Coal is in slot 1)
Spoiler

--[[
The stop command will make sure that your program will not go on indefinitely.
Somewhere in your code, you need to have an event where stop becomes true.
As soon as that happens and checkCoal() has finished executing,
the program will stop and return to the main shell (the command line you see when you boot a Turtle).
--]]
stop = false
function checkCoal()
  --First, always make sure there's one Coal left so the slot doesn't get filled up with something that isn't Coal.
  if turtle.getItemCount(1) > 1 then
	--Your mining code goes here!

  else
	print("I ran out of Coal! Please resupply slot 1 with Coal.")
	--This sleep command is to ensure that the system doesn't clog up with 'Hey I need coal' messages.
	os.sleep(10)
  end
end

--This creates an infinite loop that will cause your turtle to repeatedly go through the code in the checkCoal()
--function. The break command inside the else statement terminates the loop.
while true do
  if stop == false then
	checkCoal()

  else
	--Once you want to stop mining, stop the program with this break command, which will terminate the infinite loop.
	break
  end
end

You could also move any addtional Coal he picks up to the appropriate slot using the turtle.compareTo(SLOT) and turtle.transferTo(SLOT, QUANTITY) commands, but these are all extra, maybe unnecessary features.