15 posts
Posted 30 December 2013 - 06:14 PM
How do I make an API?
I've made this:
https://raw.github.com/IAmWolfie/wolfieAPI/master/wolfieAPIand put this into my computer and used this code:
local c = http.get("
https://raw.github.com/IAmWolfie/wolfieAPI/master/wolfieAPI")
passcode( test,right,2 )
And I get this:
c:2:attempt to call nil
???
28 posts
Posted 31 December 2013 - 06:58 AM
- Save your API to a file on y computer or turtle, say "wolfieAPI"
- In your main program use os.loadAPI ("wolfieAPI")
- reference the functions in your API by using your API name like that: wolfieAPI.passdoor (params)
if you want to download your API everytime you start your program (which I wouldn't do) you would have to http.get it and save it to a file first. If you just http.get your API it is just strings in a table. These cannot be referenced as code afaik…
See examples here:
http://computercraft...?title=Http.get)
and here:
http://computercraft.info/wiki/Fs.openAfter that you should be able to load it with os.loadAPI…
EDIT: Btw… "attempt to call nil" when using http.get means that the http functions are disabled (the default) in the computercraft config file…
Edited on 31 December 2013 - 06:14 AM
7083 posts
Location
Tasmania (AU)
Posted 31 December 2013 - 08:49 AM
You made the function local to the API, so your script couldn't access it even if you used the right function name or loaded the API correctly (… neither of which being the case).
Also remember that quotation marks are important when trying to pass values to functions, as they mark the line between variables and strings.
This tutorial may be worth a read. Bear in mind, however, that APIs are generally only useful if you intend to use the
same functions with
multiple scripts - there's not much point to them otherwise.
15 posts
Posted 31 December 2013 - 02:16 PM
Thanks, I got it working.