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

How do you make an API on only 1 computer?

Started by Geforce Fan, 29 October 2012 - 07:53 PM
Geforce Fan #1
Posted 29 October 2012 - 08:53 PM
Title says it all.
Lyqyd #2
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.
Geforce Fan #3
Posted 29 October 2012 - 09:32 PM
By only putting it on that computer? Use os.loadAPI() to load APIs that aren't in the API folder.
But how do you create the API?
ex. like how do you create what it;s going to load
snoble2022 #4
Posted 29 October 2012 - 10:17 PM
I.E. Like this
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.
Geforce Fan #5
Posted 30 October 2012 - 02:24 AM
How do you CREATE the api to load.
Lyqyd #6
Posted 30 October 2012 - 02:25 AM
The post just before yours showed you how. It's a file full of functions.
Geforce Fan #7
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") ;
?
Luanub #8
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/
remiX #9
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:

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!