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

Trying to create a api to show a simple bar getting a weird issue

Started by makeme, 02 March 2014 - 11:44 AM
makeme #1
Posted 02 March 2014 - 12:44 PM
I keep getting "bios:395: Expected string when I run :

--BarAPI Test
os.loadAPI(BarAPI)
local Current = 24
local Total = 54
local ActiveColor = "red"
local InactiveColor = "yellow"
local CursorX = 5
local CursorY = 5
local Mon = peripheral.wrap("left")
local Percent = BarAPI.Percentage(Current, Total)
terms.clear()
BarAPI.PercentBar(CursorX ,CursorY, InactiveColor, ActiveColor, Percent, Mon)

which calls this function:

--bar API
--BgColor = bar unused
--BColor = Bar Color
--Percent = Percentage that needs to be filled
--CX, Cursor X pos
--CY, Cursor Y pos
--
-- Made By SteamPunk_Devil -- CCfourm Name Makeme -- Ingame Name SteamPunk_Angel

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 = (No1 / No2) * 100
return Percent
end

function Round(num, idp)
  local mult = 10^(idp or 0)
  return math.floor(num * mult + 0.5) / mult
end

function PercentBar(CursorX, CursorY, InActiceColor, ActiveColor, n, Mon)
local FormdN = Round(n, 0)
local i = 0
local Paste = Mon or terms
Paste.setCursorPos(CursorX,CursorY)
Paste.setBackgroundColor(InActiceColor)
Paste.write("[		  ]")
Paste.setCursorPos(CursorX,CursorY)
for i < FormdN do
Paste.setBackgroundColor(ActiveColor)
Paste.write(" ")
i + 1
end
end
Edited on 02 March 2014 - 11:45 AM
CometWolf #2
Posted 02 March 2014 - 12:48 PM
does this actually work?

terms.clear()
The terminal api is called term, not terms.
Bomb Bloke #3
Posted 02 March 2014 - 12:54 PM
os.loadAPI("BarAPI")
makeme #4
Posted 02 March 2014 - 12:55 PM
ffs thats it thanks sooo much