71 posts
Location
Nerdfightaria Island
Posted 25 January 2013 - 12:41 PM
Hey, I have a problem with my program. See it it a land clearing program and it is supposed to be a customizable size one, but its not really working that way. Right now it can only go with odd width integers or it wont work. It is messing up when I try to make it go back to its start location. I have it doing alternating rows of coming forward and back, but if when it reaches its end coming forward, my reseting won't work.
this is how it is now
(I am really sorry, but I have no idea how you guys make the little white boxes for code.)
x = 0
l = 35
turtle.turnRight()
turtle.turnRight()
while x < l do
turtle.forward
x = x+1
end
x = 0
turtle.turnLeft()
while x < l do
turtle.forward
x = x+1
end
x = 0
end
How can I make it so it works when it ends going any direction?
If you want to see the entire code here it is:
http://pastebin.com/sPAUjADM
202 posts
Posted 25 January 2013 - 02:11 PM
I don't really understand what you want it to do. Could you please explain a bit farther.
71 posts
Location
Nerdfightaria Island
Posted 25 January 2013 - 04:38 PM
If I try to make it get back to its original position, it will ram into a wall if it coming towards one direction. I think I may have an idea of how to fix it though.
758 posts
Location
Budapest, Hungary
Posted 25 January 2013 - 10:52 PM
It'll be something like this
local sizeX = ({...})[1] -- just some fancy argument-getting code I like
local sizeY = ({...})[2]
local fuelSlot = ({...})[3] or 1 -- optional 3rd argument for fuel slot (default: 1) (top left slot)
-- So now you can call you program like "<program name> 6 8", and it will clear a 6x8 area
--[[
This is the 6x8 area
********# <--- This # is the turtle
********
********
********
********
********
]]
turtle.safeforward = function() -- You've got a new function! YAY! This will refuel the turtle automatically (if possible)
if turtle.getFuelLevel() == 0 then
turtle.select(fuelSlot)
while not turtle.refuel() do
print("Refuel me! (Put some coal into slot #" .. fuelSlot .. ")")
coroutine.yield()
end
end
turtle.forward()
end
local dir = false
for i = 1, sizeX do
for j = 1, sizeY do
turtle.dig()
turtle.safeforward()
end
if dir then
turtle.turnRight()
turtle.dig()
turtle.safeforward()
turtle.turnRight()
else
turtle.turnLeft()
turtle.dig()
turtle.safeforward()
turtle.turnLeft()
end
dir = not dir -- so we will know which direction to turn
end
if dir then
for j = 1, sizeY do
turtle.dig()
turtle.safeforward()
end
turtle.turnLeft()
turtle.turnLeft()
end
turtle.turnRight()
for i = 1, sizeX do
turtle.dig()
turtle.safeforward()
end
turtle.turnLeft()
print("Done")
BTW code blocks:
(code) and (/code) but enclosed by square brackets instead
So (code)local var(/local) will be
local var
Keep in mind: square brackets
2088 posts
Location
South Africa
Posted 26 January 2013 - 06:08 AM
turtle.safeforward = function() – You've got a new function! YAY! This will refuel the turtle automatically (if possible)
if turtle.getFuelLevel() == 0 then
turtle.select(fuelSlot)
while not turtle.refuel() do
print("Refuel me! (Put some coal into slot #" .. fuelSlot .. ")")
coroutine.yield()
end
end
turtle.forward()
end
I would change turtle.forward() to this for gravel safe-ness just incase…
while not turtle.forward() do
turtle.dig()
turtle.attack() -- CC 1.4 you will need this for monsters
sleep(0.4)
end
BTW code blocks:
(code) and (/code) but enclosed by square brackets instead
So (code)local var(/local) will be
local var
Keep in mind: square brackets
(/local)? xD
…
code here[[b]/[/b]code]
758 posts
Location
Budapest, Hungary
Posted 26 January 2013 - 06:11 AM
(/local)
lol I messed it up :D/>
2088 posts
Location
South Africa
Posted 26 January 2013 - 06:15 AM
(/local)
lol I messed it up :D/>
Lol yeah.
But
it is so..
simple,
don't you
see?
[[b]/[/b]code]