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

Api Loader Program

Started by Publicuser161, 17 February 2013 - 11:43 PM
Publicuser161 #1
Posted 18 February 2013 - 12:43 AM
Title: API Loader Program

Hi, I'm a bit new to programming and ComputerCraft in general, and need a bit of help making a program that loads an API after the name of such API is entered; I have just tried writing this program so I can load the "Sensors" API for OpenCC Sensors, and possibly other APIs if need be so I can load each API quickly without making an individual program to load each API, therefore cutting out massive amounts of code. I wanted an interface that read: "Please enter the name of the API you wish to add." (I know how to use print("text string" already.) and then the console read the text and insert it into the next piece of code:"os.loadAPI("ocs/apis/<API>")" where <API> was the name of the API I wished to load,API.i.e. the sensor API.
I've looked through countless wiki pages but still have no idea; any suggestions would be welcome. Thank you for your time.
Bubba #2
Posted 18 February 2013 - 05:56 AM
Just take the input and concatenate it onto the ocs/apis/
Here's an example:

write("Enter the API: ")
local api = read()
if fs.exists("ocs/apis/"..api) then --Check to make sure that the entered API exists
  os.loadAPI("ocs/apis/"..api)
else
  print("That API does not exist!")
end
Publicuser161 #3
Posted 18 February 2013 - 07:51 AM
Thanks. I'll run this.