72 posts
Posted 03 February 2016 - 12:59 PM
It is just a little question.
Is there i function where you can override a excisting function?
Like you have in ios: obj-c and swift; you have
override func prefareforSegue() {
}
3057 posts
Location
United States of America
Posted 03 February 2016 - 01:45 PM
You just define it again. Generally you'll want to retain a variable which points to the original function though.
local _print = print
print = function( ... )
_print( ... )
end
This doesn't actually change anything in the print function, but you can see how you might go about doing that.
Edit: Ninja'd
Edited on 03 February 2016 - 12:45 PM
7083 posts
Location
Tasmania (AU)
Posted 03 February 2016 - 02:29 PM
Edit: Ninja'd
Well, you were, but you actually provided valid code, so…
72 posts
Posted 03 February 2016 - 07:37 PM
Kan jou also override turtle.moveforward()?
2427 posts
Location
UK
Posted 03 February 2016 - 09:08 PM
if you want to, yes.
local oldF = turtle.forward
local oldB = turtle.back
function turtle.forward()
oldB()
end
function turtle.back()
oldF()
end
--#now I need a troll face
edit: fixed
Edited on 04 February 2016 - 10:44 AM
8543 posts
Posted 03 February 2016 - 10:08 PM
The correct function name is turtle.back.
7083 posts
Location
Tasmania (AU)
Posted 03 February 2016 - 10:45 PM
… and you cannot localise table keys.