This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Lupus_W_Tungsten's profile picture

API stacking problem

Started by Lupus_W_Tungsten, 19 November 2012 - 06:47 PM
Lupus_W_Tungsten #1
Posted 19 November 2012 - 07:47 PM
Being new to computercraft, I have been writing a function that should mine a shaft for me. I am trying to use that function in multiple programs, but I cannot use it as an api because it already has an api in it. Because I am in a server, I cannot change the minecraft folders and have to do everything in game. Is there a way to solve this without rewriting my function in the first api?
remiX #2
Posted 19 November 2012 - 09:53 PM
Put the function in your shaft program so it's not an API. If you want it to be an api, you will have to ask the server admin to add it in for you.
Lupus_W_Tungsten #3
Posted 19 November 2012 - 10:10 PM
I know I can simply rewrite all my coding into one program, but I am looking for a solution that doesn't involve endless copying.
remiX #4
Posted 19 November 2012 - 10:16 PM
Well then ask the server owner to add it into the api folder. It's not difficult to add it in.
Sammich Lord #5
Posted 20 November 2012 - 12:18 AM
Why not just use

os.loadApi("fileNameGoesHere")
I see no reason for it to HAVE to be in the APIs folder.
remiX #6
Posted 20 November 2012 - 12:43 AM
I think he wanted another way to use it other than that because he is on a server which is not his.
Sammich Lord #7
Posted 20 November 2012 - 12:51 AM
I think he wanted another way to use it other than that because he is on a server which is not his.
Why would you need to use any other function besides that? The function I provided should work on any version of ComputerCraft.
MaHuJa #8
Posted 20 November 2012 - 02:20 AM
I think the reason there's so much discussion here is because several issues are conflated.

First of all, what's the OP's real problem? What's the "endless copying" he wants to avoid?
1) Not having to copy the file to every computer.
2) Not having to copy the content into every program he writes that uses it - and especially when he updates it.

OP said he was on a server.
1) You can't really avoid this. The best you could do, if the server has http enabled, is have them (auto-)update from somewhere - like dropbox. Or (if in range) make a rednet file transfer. (Challenge mode: )Or have an automatic floppy distribution system.
2) My favorite is to dofile() the library in question.
I don't know exactly how os.loadAPI behaves, and my needs are sufficiently addressed by dofile(). Dofile runs it almost as if it had been pasted in where the dofile call is.
Kingdaro #9
Posted 20 November 2012 - 02:40 AM
This should solve your problem nicely. :(/>/>
Espen #10
Posted 20 November 2012 - 03:58 AM
I think he wanted another way to use it other than that because he is on a server which is not his.
But os.loadAPI() doesn't need the API to be in the /rom folder.
You can basically load any program you created as an API into another program. :(/>/>

This should solve your problem nicely. :(/>/>
That basically combines everything into one big file. That's ok if you don't want to edit the file anymore in the future, but for sake of clarity and keeping code logically seperated, this is not really a solution.
dofile(), loadfile(), os.loadAPI(), etc. don't actually lump the contents of the files together, but only load them at runtime.
The files themselves remain untouched, and more importantly, still logically seperated.

Not stepping on your toes here, just trying to point out the difference. :)/>/>