Jump to content




[Turtle] Auto refuel via Enderchest.


  • You cannot reply to this topic
9 replies to this topic

#1 JoePwnz

  • Members
  • 13 posts

Posted 06 April 2014 - 09:14 PM

Dear Community,
im quite new to the Lua coding, and never did coding before thats why im asking you guys..
i just made a Farming turtle and got it running with a refuel command n stuff.. just a basic code
for refuelling, with if fuel is less then 10 = refuel and i want to automate it with enderchest..
what i want to do is something like

when the turtle checks for fuel there should be a situation where the turtle runs out of the selected slot
and detects it.. Then it should place a enderchest above take a bit coal out, pick up the chest and continue with Farming

Sorry for my bad english tho im from Germany :)

Greets from JoePwnz!

I would love to hear a answer!

#2 CometWolf

  • Members
  • 1,283 posts

Posted 06 April 2014 - 09:36 PM

This is pretty simple, just tell the turtle to select the enderchest slot with turtle.select(), then place it using turtle.place(). Once the chest is in place use turtle.suck() to suck items out of it, then use turtle.refuel to use those items for refueling. Idk how good you need this functionality wise, but you might want to check the block you wanna place it in using turtle.detect() beforehand to confirm that the turtle can actually place it and such.

Here's a function from my own api for just such a thing. Keep in mind that it uses openP to acess specific slots of the enderchest though. You can't do that with vanilla CC.
Spoiler
This is simply provided as an example though, and won't work without my api.

Edited by CometWolf, 06 April 2014 - 09:36 PM.


#3 JoePwnz

  • Members
  • 13 posts

Posted 06 April 2014 - 10:30 PM

Thanks for the answer!
Well i just want to add a bit more of coding because i want to add a else function..
i got at the moment this little function (was just trying to add a else function but i dont know how) :

(here is a function)
if turtle.getFuelLevel() < 10 then
turtle.select(1)
turtle.refuel(1)
else
turtle.select(15)
turtle.placeUp()
turtle.suck(5)
turtle.digUp()
end
end
but im just to stupid to make one..

#4 CometWolf

  • Members
  • 1,283 posts

Posted 06 April 2014 - 10:41 PM

else what? seems to me like you've got it all in place, except you might want to attempt to refuel again after getting an item from the chest. Also im guessing you use slot 1 for fuel, so have the turtle select that slot prior to using suck, then reselect the enderChest slot before picking it up again.

#5 JoePwnz

  • Members
  • 13 posts

Posted 06 April 2014 - 10:55 PM

well the problem is that the turtle is just placing the chest and then it starts walking and doing its thing, but not picking it up again..
i thought when i add a "else" its gonna check if the code above works and if it doesnt, its gonna use the code below else.. the problem is, for me as a newbie its very hard to add functions because you have to search in the internet for codes and try to learn it from yourself.. im just trying to figure out how..i dont even want to add the entire code because you guys would get a heart attack :D

Edited by JoePwnz, 06 April 2014 - 11:02 PM.


#6 CometWolf

  • Members
  • 1,283 posts

Posted 06 April 2014 - 10:59 PM

You're using a mining turtle i presume? They're the only ones who could break an enderchest.

#7 JoePwnz

  • Members
  • 13 posts

Posted 06 April 2014 - 11:08 PM

Im using a Farming Turtle, but i used a Mining turtle now.. and nothing works with that..
Alright check out those 2 codes

!!this is a newbie code be aware!!

Regular Refill without enderchest: http://pastebin.com/jkeQQmu7

(doesnt work at all, tried with mining and farming turtle)My try with enderchest refill: http://pastebin.com/GiKQi0E1

Edited by JoePwnz, 06 April 2014 - 11:15 PM.


#8 blipman17

  • Members
  • 92 posts

Posted 07 April 2014 - 06:49 PM

View PostJoePwnz, on 06 April 2014 - 11:08 PM, said:

tried with mining and farming turtle)My try with enderchest refill: http://pastebin.com/GiKQi0E1

lets get through your function for refuelling
local function checkFuel()
  if turtle.getFuelLevel() < 10 then   -- if you are low on fuel then select slot 1 and refuel. this does work if you would have valid fuel there.
	  turtle.select(1)
	  turtle.refuel(1)
  else				-- if ou are not low on fuel then select slot 15, place an enderchest up, suck any item from the front and then dig up the enderchest, placing it back in slot 15.
	  turtle.select(15)
	  turtle.placeUp()
	  turtle.suck(5)
	  turtle.digUp()
  end
end

you might want to try this.
function checkFuel() --checks if there is enough fuel and refuels when neded.

	if turtle.getFuelLevel()<10 then  --if you are low on fuel

		print("refueling")
		turtle.select(15)  --select the enderchest
		turtle.placeUp()  --place the enderchest above you
		turtle.suckUp() --suck some fuel from the above enderchest into the current selected slot. (you cannot specify any amounth or from which slot.)
		turtle.refuell(1)  --refuel with one piece of fuel
		turtle.dropUp(63)  --dump the rest of the fuel back in the enderchest. (can be left out of the code.)
		turtle.digUp()  --digs up the enderchest above you and places it in your current selected iventory.

	else  --if you are not low on fuel.

		print("not low on fuel, carrying on with business. mining lasers n stuff.")

	end
end

You would need a mining turtle for this, because an enderchest is not a farming item. So it can't be picked up with a hoe. It might be better to have a chest with fuel on a set spot where the turtle will be a lot of time, and have him refuell over there.

Also, if you didn't know. Computercraft has an own Wiki which can be verry helpfull with build in functions.
http://computercraft...i/Category:APIs
especcially this one,
http://computercraft...ki/Turtle_(API)

Edited by blipman17, 07 April 2014 - 06:45 PM.


#9 JoePwnz

  • Members
  • 13 posts

Posted 08 April 2014 - 11:22 PM

Thanks! i realy needed a guy who shows me what i did wrong, and tells me how to do it better! I had the problem i only thought about adding a else function because it needs to do something else when number 1 is not true... And i totaly forgot to add a code at my topic.. thanks for the help, and keep coding!

#10 blipman17

  • Members
  • 92 posts

Posted 09 April 2014 - 04:16 PM

What i always try to do when I get stuck on some not working code is taking a piece of paper, start doing stuff manually from there and figure where I went wrong. It helps if you would first make a little draft from the steps you have to take. Remember, a computer is stupid. It is just way faster than you in doing stuff you want.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users