7 posts
Posted 17 April 2012 - 05:24 PM
Hey,
I am new to ComputerCraft and Lua but not at things like java/html/php/.net etc. So I know a lot of things I can use in Lua.
I am making a new api for a turtle and here is the code ive got:
function rails()
x=0
turtle.up()
while not turtle.detect() do
while x >=0 and x < 10 do
x = x+1
turtle.select(1)
turtle.placeDown()
turtle.forward()
end
while x>9 and x <19 do
x = x+1
turtle.select(2)
turtle.placeDown()
turtle.forward()
end
if x > 18 or x < 0 then
x = 0
end
end
end
I want a turtle to place tracks. x is the amount of tracks need to be placed before switch to powered rails. 0 to 9 are normal tracks and 10 to 18 are booster rails.
My question is:
Why does it do everything but placing the tracks?
Thanks
474 posts
Posted 17 April 2012 - 06:26 PM
Turtle's can't place rails, rails are items with metadatas, meaning they're a item, but on right click, it places the block at the X, Y, and Z position of the crosshair. Turtle's can't place items in the current version.
1604 posts
Posted 17 April 2012 - 06:34 PM
The code seems to be fine, although I would change the variable x to a local one: local x = 0, but it should work anyway.
As you are checking if there's a block in front of the turtle, I suppose it's on the ground. If it is, that's the problem: you are trying to place the rails below the turtle, but there's already a block in there (the dirt, stone, whatever the turtle is on). Try changing the turtle.placeDown() to turtle.place(), that should fix the problem.
Turtle's can't place rails, rails are items with metadatas, meaning they're a item, but on right click, it places the block at the X, Y, and Z position of the crosshair. Turtle's can't place items in the current version.
Actually, turtles can place rails. I thought they couldn't, but just tried it and works fine.
92 posts
Posted 17 April 2012 - 06:36 PM
It works in 1.3. What version are you using MysticT? Has it changed in the latest version?
7 posts
Posted 17 April 2012 - 06:58 PM
The code seems to be fine, although I would change the variable x to a local one: local x = 0, but it should work anyway.
As you are checking if there's a block in front of the turtle, I suppose it's on the ground. If it is, that's the problem: you are trying to place the rails below the turtle, but there's already a block in there (the dirt, stone, whatever the turtle is on). Try changing the turtle.placeDown() to turtle.place(), that should fix the problem.
Turtle's can't place rails, rails are items with metadatas, meaning they're a item, but on right click, it places the block at the X, Y, and Z position of the crosshair. Turtle's can't place items in the current version.
Actually, turtles can place rails. I thought they couldn't, but just tried it and works fine.
Well yes I try to place it under the turtle but it first fly's up so there is no block underneath it.
1604 posts
Posted 17 April 2012 - 07:12 PM
Well yes I try to place it under the turtle but it first fly's up so there is no block underneath it.
Ups, didn't see that line :)/>/>
I assume the turtle has rails in the correct slots (the top left and top middle are the slots 1 and 2).
Does the turtle move when you run the code? if it doesn't there's something wrong in the code, but I don't see what it is now.
7 posts
Posted 17 April 2012 - 07:50 PM
Well yes I try to place it under the turtle but it first fly's up so there is no block underneath it.
Ups, didn't see that line :)/>/>
I assume the turtle has rails in the correct slots (the top left and top middle are the slots 1 and 2).
Does the turtle move when you run the code? if it doesn't there's something wrong in the code, but I don't see what it is now.
Everything goes right but only at the rails it fails… its moving, rotating, shifting from slots, everything. so this is pretty weird if you can place rails with turtles.
I am using Tekkit 2.1.1 that may help
1604 posts
Posted 17 April 2012 - 09:06 PM
It might be a Tekkit bug then, cause there's no errors in the code or the setup (at least I don't see any).
I'll try the code to see if it's a Tekkit or CC bug.
Edit: just tested, it works fine. Must be Tekkit problem.
Edited on 17 April 2012 - 07:20 PM
92 posts
Posted 17 April 2012 - 09:26 PM
I'm using Tekkit and that code works for me.
You can only use vanilla rails and powered rails.
2217 posts
Location
3232235883
Posted 22 April 2012 - 01:32 AM
the problem is all turtle.detect functions always returns true
i am having this problem and this is why alot of programs i see are broken