This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
How do you make an API on only 1 computer?
Started by Geforce Fan, 29 October 2012 - 07:53 PMPosted 29 October 2012 - 08:53 PM
Title says it all.
Posted 29 October 2012 - 09:09 PM
By only putting it on that computer? Use os.loadAPI() to load APIs that aren't in the API folder.
Posted 29 October 2012 - 09:32 PM
But how do you create the API?By only putting it on that computer? Use os.loadAPI() to load APIs that aren't in the API folder.
ex. like how do you create what it;s going to load
Posted 29 October 2012 - 10:17 PM
I.E. Like this
EVERYTHING in the API must be a function or else when you load it or call from it, It will run it.
Spoiler
function printHello()
print("hello")
end
EVERYTHING in the API must be a function or else when you load it or call from it, It will run it.
Posted 30 October 2012 - 02:24 AM
How do you CREATE the api to load.
Posted 30 October 2012 - 02:25 AM
The post just before yours showed you how. It's a file full of functions.
Posted 30 October 2012 - 02:33 AM
So just use the edit program
like "edit file" then do your API then to load it os.loadAPI("file") ;
?
like "edit file" then do your API then to load it os.loadAPI("file") ;
?
Posted 30 October 2012 - 02:54 AM
Making an API is very simple if you can write a program you can write an API. The only difference is the API does not need to be code that runs, it just needs functions that you can call from another program and have them run.
If you're not sure what to do then either
A- look at an existing API, there are several in /rom/apis
B- Read the tutorial http://www.computerc...reating-an-api/
If you're not sure what to do then either
A- look at an existing API, there are several in /rom/apis
B- Read the tutorial http://www.computerc...reating-an-api/
Posted 30 October 2012 - 09:32 AM
1. Go into rom/apis and create a file.
2. The file must ONLY contain functions like this:
4. To use a function:
If the API file name is func, to use them you would do this:
2. The file must ONLY contain functions like this:
function derp()
print("You called the derp function")
end
function readText(file)
if fs.exists(file) then
file = fs.open(file,"r")
text = file.readAll()
fs.close()
print(text)
else
print(file.." does not exists!")
end
3. If it is in the rom/api, you will not need to use os.loadAPI("filename") to load it. Only use that if it is in the ID folder of the computer.4. To use a function:
If the API file name is func, to use them you would do this:
func.derp()
func.readText("derp")
5. And that should be all!