Is there a way to create a function that over-writes an existing function while still being able to call the original function ?
Let me give an example. I wish to have the turtle.forward() command move my turtle up ie turtle.up as well as forward by issuing the turtle.forward command
Thanks
0
Noob needs help with replacing turtle functions..
Started by R4tt3xx, Jun 10 2013 10:52 AM
7 replies to this topic
#1
Posted 10 June 2013 - 10:52 AM
#2
Posted 10 June 2013 - 11:35 AM
Split into new topic.
Yes, you can. Why not just make a new function that does both and use it instead, though? If you really need exactly this, which I suspect isn't the best solution, you'd just:
Yes, you can. Why not just make a new function that does both and use it instead, though? If you really need exactly this, which I suspect isn't the best solution, you'd just:
local oldForward = turtle.forward turtle.forward = function() if oldForward() and turtle.up() then return true else return false end end
#3
Posted 10 June 2013 - 12:07 PM
My idea:
local oldUp = turtle.up local oldForward = turtle.forward function turtle.forward() oldUp() end function turtle.up() oldForward() end
#4
Posted 10 June 2013 - 12:32 PM
That does not do what OP asked.
#5
Posted 10 June 2013 - 12:50 PM
Here's a oneliner to replace Feack's code.
turtle.up, turtle.forward = turtle.forward, turtle.up
To answer the OP fully,
turtle.up, turtle.forward = turtle.forward, turtle.up
To answer the OP fully,
turtle.rawforward = turtle.forward turtle.forward = function() return turtle.rawforward() and turtle.up() end
#6
Posted 10 June 2013 - 12:54 PM
^ And it even returns if both moves were succussful! +1
#8
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users