Edited by Signify, 14 August 2014 - 07:43 PM.
How to overwrite default programs/commands
#1
Posted 14 August 2014 - 07:22 PM
#2
Posted 14 August 2014 - 07:48 PM
#3
Posted 14 August 2014 - 07:48 PM
api_name.function(parameters) --eg signify.forward(3)which would if it's set up would move the turtle forward 3 times
#4
Posted 14 August 2014 - 07:53 PM
Cranium, on 14 August 2014 - 07:48 PM, said:
While that may work for executing programs from the shell, what about when programming? I want to overwrite turtle.forward(), since putting it in the root directory would not automatically load the API as turtle, how exactly would I do this? Could I replace go and refuel without spamming their root with a ton of replacements? Or would I have to have the api named turtle and somehow replace their startup script so it automatically loads 'turtle' overwriting the previous one? Since it is an API, I can't use shell.getRunningProgram() to get it's name, rename it to turtle only the fly, move it to the root directory, then load it.
And if I loaded turtle over the current one, does that mean I'd have to provide ALL of the turtle functions or would it just overwrite the ones I've got and when it couldn't find it from mine, it'd look elsewhere after that?
Edited by Signify, 14 August 2014 - 07:58 PM.
#5
Posted 14 August 2014 - 07:57 PM
local oldForward = turtle.forward function turtle.forward(num) return oldForward(num) endBasically.
#6
Posted 14 August 2014 - 08:01 PM
Cranium, on 14 August 2014 - 07:57 PM, said:
local oldForward = turtle.forward function turtle.forward(num) return oldForward(num) endBasically.
So in my API, I could literally say:
turtle.forward = myForward?
Or would I have to:
holderFunction = turtle.forward turtle.forward = myforward function myforward() holderFunction() end
Edited by Signify, 14 August 2014 - 08:05 PM.
#7
Posted 14 August 2014 - 08:06 PM
Signify, on 14 August 2014 - 08:01 PM, said:
No. First, you have to make a local backup of the turtle function, because you need to use it in your code, and second when replacing functions don't use brackets.
You should make your function like Cranium said:
local oldForward = turtle.forward turtle.forward = function() -- logic, loops, bla bla bla oldForward() end
Edited by flaghacker, 14 August 2014 - 10:08 PM.
#8
Posted 14 August 2014 - 08:09 PM
flaghacker, on 14 August 2014 - 08:06 PM, said:
You should make your function like Cranium said:
local oldForward = turtle.forward turtle.forward = function() -- logic, loops, bla bla bla turtle.forward() end
If you're making a local backup, why wouldn't it be:
local oldForward = turtle.forward turtle.forward = function() -- logic, loops, bla bla bla oldForward() end
But even if I overwrite those, since this is happening within an API, wouldn't the program still executing my api still have to reference them as api.turtle.function() ?
Edited by Signify, 14 August 2014 - 08:19 PM.
#9
Posted 14 August 2014 - 08:45 PM
Signify, on 14 August 2014 - 08:09 PM, said:
local oldForward = turtle.forward turtle.forward = function() -- logic, loops, bla bla bla oldForward() end
But even if I overwrite those, since this is happening within an API, wouldn't the program still executing my api still have to reference them as api.turtle.function() ?
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











