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

Getting a table through a function

Started by makeme, 28 February 2014 - 07:47 PM
makeme #1
Posted 28 February 2014 - 08:47 PM
I've been trying to create a tank monitoring program using OpenPeripherals but keep running into issues getting the tank info from the function to the main program. Could someone work out what I've done wrong?

I've made a simple installer: pastebin get uTTAd79X Installer

SpoilerProgram

--SteamPunk_Devil's Tank Monitor!
print("SteamPunk_Devil's Tank Monitor V0.01")
os.loadAPI("API/steAmPI")

local tank = peripheral.wrap("back")
tankData = tankInfo(tank)
print(tankData[1])
API

The Function is tankInfo()

--steAmPI By SteamPunk_Devil IGN - SteamPunk_Angel--
--Feel free to edit this in anyway as long as you credit me(and tell me if you can)--
--Initials: SPD = SteamPunk_Devil,

print("Successfully Loaded steAmPI, Version: Indev V0.01, By: SPD, Release Date: 28/02/2014") --Change release date and version every full release, The "By" is the initials of whoever release it and full names can be found in the header

function version() --Displays version
print("Indev V0.01, By SPD, Release Date: 28/02/2014") --Same as above
end

function tankInfo(tank) -- Getting info from RC tanks
tableInfo = tank.getTankInfo("unknown")
return tableInfo
end

function Percentage(current,total) --returns One number as a percentage of the second one --TBD Round to a Decimal place
local No1 = current
local No2 = total
local Percent = (current / total) * 100
return Percent
end

function Buckets(miliBuckets) -- turns milibuckets to buckets
local total = miliBuckets / 1000
return total
end

Thanks
Edited on 28 February 2014 - 07:47 PM
CometWolf #2
Posted 28 February 2014 - 09:54 PM
You're using the loaded api functions wrong, they're loaded into a table named the same as your api, and my god what an annoying api name that is.

tankData = steAmPI.tankInfo(tank)
makeme #3
Posted 28 February 2014 - 09:58 PM
yeah the name is stupid thanks I'm still getting used to functions and tables