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
[question] override old turtle.forward?
Started by LuaEclipser, Mar 09 2013 12:19 PM
5 replies to this topic
#1
Posted 09 March 2013 - 12:19 PM
#2
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.
#3
Posted 09 March 2013 - 12:24 PM
Easy. Use this:
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.
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.
#6
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
})
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












