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

Need Help Coding

Started by John Smith, 04 May 2014 - 01:44 PM
John Smith #1
Posted 04 May 2014 - 03:44 PM
Hello I have just started using ComputerCaft and I was trying to make a coding so that my turtle can shear a sheep go to the right 2 times and when the shears break it can grab a new one however I cant seem to get it to work and I have looked at many others so I really need help. Basically here is what I need.



A coding to..

Shear a sheep and move on the the next two.

Grab a new set of shears when the old ones break.

repeat in a loop.



I hope its not to much to ask for!
Edited on 04 May 2014 - 04:59 PM
jewelshisen #2
Posted 04 May 2014 - 05:40 PM
This place is for you to get help with code you have made, not to get people to make the code for you
John Smith #3
Posted 04 May 2014 - 05:49 PM
I wonder why the mod accepted my thread im new and it says I need a mods approval and it seems to be approved so clearly its both I guess
and btw if you dont want to help please just dont comment.
Lyqyd #4
Posted 04 May 2014 - 06:25 PM
A topic getting approved usually just means it isn't a spam topic. He was giving you a friendly notice that we generally don't create programs on request here. Play nice, please.
John Smith #5
Posted 04 May 2014 - 06:27 PM
So I'm coding a turtle for shearing a sheep and I want it to move it to move but it wont. I also want it to shear yet also it wont do that to, here is my code. Please I need help I'm a beginner and I don't entirety understand this.



while true do –never ending loop
turtle.place()
turtle.select(2)
turtle.Down()
turtle. turnRight()
turte.forward()
turtle.Down()
turtle.select(1)
turtle.suckUp()
while turtle.getItemCount(1) == 0 do - repearts this until there's an item in slot 1
turtle.select(1)
turtle.suckUp()
end
end
I have no idea what I did wrong and I have no idea what to do! Help maybe?
awsmazinggenius #6
Posted 04 May 2014 - 06:29 PM
You say that you have tried; can you show that code?

Also, can you put up a screenshot/something that shows us where to get the new shears from? Also, what about dropping off the wool when the turtle gets full?
Lyqyd #7
Posted 04 May 2014 - 06:33 PM
Threads merged. Please stick to one topic for all questions about a given piece of code.
John Smith #8
Posted 04 May 2014 - 06:37 PM
Okay sorry





there you go images
blipman17 #9
Posted 04 May 2014 - 07:31 PM
For what do you need help? Please use proper grammar, else it is hard for us to read. I understand if you are not English, but please try a little harder.
John Smith #10
Posted 04 May 2014 - 07:54 PM
I want to find out whats wrong with my code I want it to
shear the sheep and move on to the other sheeps
but it wont do any of that
Bomb Bloke #11
Posted 05 May 2014 - 12:15 AM
The turtle won't move without fuel.

Shearing requires the target to be sheared to be directly next to the turtle. Given that your sheep are underneath it, you probably want to be using turtle.placeDown().

To determine whether the turtle still has a pair of shears in its first slot, you could hold a wool block in eg the last (sixteenth) inventory slot, then do a check like this:

turtle.select(1)
if turtle.getItemCount(1) == 0 or turtle.compareTo(16) then
  -- Shears slot is either empty or has been filled with wool, shears are therefore broken, go get another pair.
end

Your script is still missing code to drop the wool and to move the turtle back after getting new shears, but once you've got it moving and can experiment properly you'll hopefully be ok from there. Be sure to read up on the rest of the turtle API if you haven't already.
John Smith #12
Posted 05 May 2014 - 04:35 AM
The turtle won't move without fuel.

Shearing requires the target to be sheared to be directly next to the turtle. Given that your sheep are underneath it, you probably want to be using turtle.placeDown().

To determine whether the turtle still has a pair of shears in its first slot, you could hold a wool block in eg the last (sixteenth) inventory slot, then do a check like this:

turtle.select(1)
if turtle.getItemCount(1) == 0 or turtle.compareTo(16) then
  -- Shears slot is either empty or has been filled with wool, shears are therefore broken, go get another pair.
end

Your script is still missing code to drop the wool and to move the turtle back after getting new shears, but once you've got it moving and can experiment properly you'll hopefully be ok from there. Be sure to read up on the rest of the turtle API if you haven't already.

I've been trying all day do you have some kind of code that might show me how I can fix mine?
Bomb Bloke #13
Posted 05 May 2014 - 04:50 AM
Explain how what it IS doing, and I'll see what I can do.
awsmazinggenius #14
Posted 05 May 2014 - 05:30 AM
Depending on what other mods you play with and if you have power setup and of you have MFR, you may be interested in the MFR Rancher (http://ftbwiki.org/Rancher). It will do pretty much exactly what you want to do (shear sheep), among other things. Since Turtles do require fuel to function anyways, this might be a simpler option, depending on if you have power set up.
blipman17 #15
Posted 05 May 2014 - 09:14 AM
Why are you letting your turtle go so much down? I mean, you want him to go to the left wnd right, right?
John Smith #16
Posted 05 May 2014 - 03:38 PM
Explain how what it IS doing, and I'll see what I can do.

its ignoring the stuff i just put in ill retry when I get back from school maybe I have a typo
blipman17 #17
Posted 05 May 2014 - 06:34 PM
does it give an error?
if yes, then what error?
if no, what exact actions don't work?
until when does your code still work as intended?

we don't know exactly what you want, even if it seems so simple to you.
Lignum #18
Posted 05 May 2014 - 07:44 PM
its ignoring the stuff i just put in ill retry when I get back from school maybe I have a typo
Do you mean that things like turtle.forward() don't do anything at all?
If that's the case, make sure the turtle has enough fuel (1 coal per block) or turn off fuel entirely in the config file.
Edited on 05 May 2014 - 05:44 PM
John Smith #19
Posted 06 May 2014 - 02:16 AM
things like turtle.forward

I want the following things to work as of my turtle.

-To Shear Sheep
-To Get New Shears When Old Ones Broken
-To Move On To The Next Sheep

That's all I am asking for…
Lyqyd #20
Posted 06 May 2014 - 07:29 AM
Okay, so break it down. What steps does the turtle need to take for each of those actions? You've got a good start on planning your program, but you need to invest the work in actually putting it together. We're not here to do it for you, just help you get there yourself.
CreeperGoBoom #21
Posted 06 May 2014 - 08:16 AM
first with no programs running, enter id and press enter, you should get a number next to a #
go to pastebin.com
open your saves folder for whatever mod pack you are using, go into computer, then into the number that came up, you should see some FILES, (no extension)
open the program you made using notepad or even better, notepad++, press ctrl+a, then ctrl+c, now go to pastebin.com, paste it in the text field using ctrl+v, select LUA next to syntax highlighting, make sure expiration wont delete it too soon, reccommend registering to pastebin so you can easily manage your pastes, then click done, now give us the link to the page that has just come up

do this for any code help you need, makes it tonnes easier for us to read it also ;)/>

i see you have plenty of fuel from your screenshot, but we need a more streamlined code paste

also, indent your statements, code blocks are ugly enough as it is ;)/>, trust me you'll get more preference for help as the code is easier to read

example

such and such
if this = that then
  do this
else
  do this
end

-----

while true do
  if this = that then
  if this = something else then
	do this
  end
end

im no coding expert but i can help, this is one of many steps in the right direction :)/>
help us understand the problem exactly, and we'll do what we can but you must put in the hard yards first ;)/>
Edited on 06 May 2014 - 07:49 AM