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

[WIP][API]amtraAPI v0.2

Started by amtra5, 18 April 2013 - 09:05 PM
amtra5 #1
Posted 18 April 2013 - 11:05 PM
This is a wip API that will contain miscellaneous functions to assist programming. If you feel something is missing from my API that you would like me to implement, please suggest it! Also, it would be greatly appreciated if you could help me clean up my code, as this is my first program/API on the forums ;)/>

Download:
http://pastebin.com/VEqkcSgN
pastebin get VEqkcSgN

Credits:
theoriginalbit-For improving on my code
BigSHinyToys-For suggesting an improvement

Note:I will gladly accept modifications to how my code works efficiency wise, however please don't post modifications that change what each function returns, as this could serverely break a program using my API
BigSHinyToys #2
Posted 18 April 2013 - 11:28 PM
A function you might find useful is rs.getSides()
Example usage :
Spoiler

local function listDevice() -- decalre a function
    local tReturn = {} -- decalre a table
    for _,sSide in pairs(rs.getSides()) do -- go throught a list provided by fs.getSides
	    if peripheral.isPresent(sSide) then
		    table.insert(tReturn,{side = sSide,device = peripheral.getType(sSide)})
	    end
    end
    return tReturn
end
local tDevices = listDevice()
for i = 1,#tDevices do
    print(tDevices[i].side.." Type : "..tDevices[i].device)
end
theoriginalbit #3
Posted 19 April 2013 - 12:58 AM
you have an error on line #1 … comments are – not //
amtra5 #4
Posted 19 April 2013 - 08:50 PM
oops