When try to access the gui api after loading it, it throws this message: attempt to index a nil value
Here is the API:
--Variables--
local buttonsMain = {}
local keysMain = {}
--Functions--
local function LocalAddField(v)
buttonsMain[#buttonsMain+1] = {v[1],v[2],v[1]+v[3]-1,v[2]+v[4]-1,v[5]}
end
function AddField(v)
if not pcall(LocalAddField,v) then
print([[
Usage:
As an argument pass a table structured like this:
{
xPos,
yPos,
wide,
height,
returnValue,
}
]])
end
end
local function LocalDrawButton(v)
if v[5] ~= "nil" then
paintutils.drawFilledBox(v[1],v[2],v[1]+v[3]-1,v[2]+v[4]-1,v[5])
end
term.setTextColor(v[9])
term.setCursorPos(v[1]+v[6]-1,v[2]+v[7]-1)
local textToPrint = string.sub(v[8],1,v[1]+v[3]-v[6])
term.write(textToPrint)
buttonsMain[#buttonsMain+1] = {v[1],v[2],v[1]+v[3]-1,v[2]+v[4]-1,v[10]}
end
function DrawButton(v)
if not pcall(LocalDrawButton,v) then
print([[
Usage:
As an argument pass a table structured like this:
{
xPos,
yPos,
wide,
height,
colorOfButton,
inButtonXPosOfLabel,
inButtonYPosOfLabel,
label,
textColor,
returnValue,
}
You can have the option to not use the background color.
You can do this by simply setting color of button to nil.
]])
end
end
function DetectButtonOrKeyHit()
while true do
local event, button, x, y
repeat
event, button, x, y = os.pullEvent()
until (event == "mouse_click" and buttonsToTest ~= nil) or (event == "key" and keysToTest ~= nil)
if event == "mouse_click" then
for i,v in pairs(buttonsMain) do
if v[1] <= x and x <= v[3] and v[2] <= y and y <= v[4] then
return {v[5], button, x, y}
end
end
elseif event == "key" then
for i,v in pairs(keysMain) do
if button == v[1] then
return {v[2]}
end
end
end
end
end
function ResetButtons()
buttonsMain = {}
end
local function LocalCPrint(v)
if not v[6]t == "nil" then
v[1] = string.sub(v[1],1,v[6])
end
term.setTextColor(v[2])
if not v[3] == nil then
term.setBackgroundColor(v[3])
end
term.setCursorPos(v[4],v[5])
term.write(v[1])
end
function cPrint(v)
if not pcall(LocalCPrint,v) then
print([[
Usage:
Arguments are as follws:
{
Text to print
Text color
Background color
xPos
yPos
Maximal lenght of the string
}
Maximal lenght of the string can be left "nil" with qoutes
]])
end
end
This is how I call it
gui.ResetButtons()
gui.cPrint({"Login",colors.black,"nil",3,3})
gui.cPrint({"Username: >",colors.gray,"nil",3,6})
gui.cPrint({"Password: >",colors.gray,"nil",3,8})
gui.AddField({15,6,35,6,"userField"})
Thanks guys,
I hope you can help me ;)/>