233 posts
Location
Cleveland, Ohio
Posted 09 March 2013 - 12:19 PM
this is a small question, but i want to know how to override the original turtle.forward() with a turtle.forward that will act like this
turtle.forward(2)
will go forward 2
423 posts
Location
AfterLifeLochie's "Dungeon", Australia
Posted 09 March 2013 - 12:23 PM
local turtleForward = turtle.forward
turtle.forward = function(times)
for i=1, times do
turtleForward()
end
end
I need coffee.
436 posts
Posted 09 March 2013 - 12:24 PM
Easy. Use this:
oldFor = turtle.forward
turtle.forward = function(iSteps)
local i = 0
for i = 1, iSteps do
oldFor()
end
end
--Your code here
turtle.forward = oldFor
Should work. I think.
However, this only works on a per-program basis. If you want it to work on a computer, leave off the las line, and put it in startup.
233 posts
Location
Cleveland, Ohio
Posted 09 March 2013 - 12:24 PM
local turtleForward = turtle.forward
turtle.forward = function(times)
for i=1, times do
turtleForward()
end
end
I need coffee.
lol
thank you guys
1511 posts
Location
Pennsylvania
Posted 09 March 2013 - 12:57 PM
I need coffee.
Lol, been working too hard? :P/>
148 posts
Posted 09 March 2013 - 01:19 PM
Or the metatable way (cause they're awesome!)
turtle.forward = setmetatable({forward = turtle.forward}, {__call = function(self, n)
for i = 1, n do
self.forward()
end
end
})