I keep getting this error, and I have no clue what I am doing wrong. I've looked at it for several days and even rewrote the entire function(chat function in run.lua). I've commented out the line that accesses api_button, when it calls .createButton(), everything else runs smooth. Worse, is I do this in my mainMenu() function and it works. I've included my pastebin, encase the issue is more then the functions I've added. I apologize upfront for any improper formating, or crappy functionality, I was in the process of rewriting the entire run.lua file, when I ran into this issue.
Error
api_button:10: index expected, got number
api_button.lua
--[[
FILENAME: api_button.lua(API)
AUTHOR: Donald R. Valverde (Cavious)
VERSION: 1.0-ALPHA
--]]
local button = {}
function createButton(list, id, text, fontColor, backgroundColor, xPos, yPos, funct)
button[id] = {}
button[id]["text"] = text
button[id]["fontColor"] = fontColor
button[id]["backgroundColor"] = backgroundColor
button[id]["xPos"] = xPos
button[id]["yPos"] = yPos
button[id]["funct"] = funct
table.insert(list, button[id])
end
function removeButton(list, id)
table.remove(list, id)
end
function drawButtons(output, list)
for i = 1, #list do
output.setCursorPos(list[i].xPos, list[i].yPos)
output.setTextColor(list[i].fontColor)
output.setBackgroundColor(list[i].backgroundColor)
output.write(list[i].text)
end
end
function drawButton(output, list, i)
output.setCursorPos(list[i].xPos, list[i].yPos)
output.setTextColor(list[i].fontColor)
output.setBackgroundColor(list[i].backgroundColor)
output.write(list[i].text)
end
function runButtonEvent(output, buttonList, activeButtonColor, inactiveButtonColor, event_type)
state = true
while(state) do
event, button, xPos, yPos = os.pullEvent(event_type)
for i = 1, #buttonList do
if(yPos == buttonList[i].yPos and xPos >= buttonList[i].xPos and xPos < (buttonList[i].text:len() + buttonList[i].xPos)) then
buttonList[i].backgroundColor = activeButtonColor
api_button.drawButton(output, buttonList, i)
os.sleep(0.5)
buttonList[i].backgroundColor = inactiveButtonColor
api_button.drawButton(output, buttonList, i)
os.sleep(0.5)
buttonList[i].funct()
state = false
end
end
end
end
run.lua(Chat Function)
function chat()
local buttonList = {}
local image = paintutils.loadImage("gb_os/img/image_chat")
paintutils.drawImage(image, 1, 1)
local image = paintutils.loadImage("gb_os/img/image_chat_end")
paintutils.drawImage(image, 25, 1)
api_button.createButton(buttonList, "btn_back", "Back", colors.white, colors.orange, 2, 18, mainMenu)
api_button.drawButtons(term, buttonList)
state = true
while(state) do
local event = {os.pullEvent()}
if(event[1] == "mouse_click") then
local xPos = event[3]
local yPos = event[4]
for i = 1, #buttonList do
if(yPos == buttonList[i].yPos and xPos >= buttonList[i].xPos and xPos < (buttonList[i].text:len() + buttonList[i].xPos)) then
buttonList[i].backgroundColor = colors.lime
api_button.drawButton(term, buttonList, i)
os.sleep(0.5)
buttonList[i].backgroundColor = colors.green
api_button.drawButton(term, buttonList, i)
os.sleep(0.5)
buttonList[i].funct()
if(buttonList[i].id == "btn_back") then
state = false
position_y = 2
end
end
end
end
if(event[1] == "key") then
if(event[2] == 28) then
local input = chatBoxClick()
sendToScreen(input)
--sendToServer(input)
end
end
end
end
Pastebin Links:
run.lua
api_button.lua
Thank you in advance,
Donald R. Vaverde (Cavious)