buttons[name]["funcF"]
gets called; asking for an equals sign since it thinks that I want to assign a value to buttons[name]["funcF"] (I understand why this is happening).Does anyone know the proper syntax for this? I just need it so when I call
buttons[name]["funcF"]
it will run getInfo("reactorComp", "turnOff")
, etc (there will be numerous different buttons with different functions, so the code should be generalised).Relevant Code:
----- Relevant Code -----
-- Buttons
buttons = {}
buttons["reactorToggle"] = {funcF = getInfo("reactorComp", "turnOff"), funcT = getInfo("reactorComp", "turnOn")}
-- Called when the monitor is clicked, used to check if a button is pressed, and if so execute the relative function
function checkButtons(x, y)
for name, temp in pairs(buttons) do
local button = buttons[name]
if button["active"] == true and y == button["yPos"] then
if x >= button["xPos"] and x <= button["xPos"] + math.floor(button["width"]/2) then
buttons[name]["funcF"] -- error
elseif x >= (button["xPos"] + math.ceil(button["width"]/2)) and x <= (button["xPos"] + button["width"]) then
buttons[name]["funcT"]
end
end
end
end
-- Calling the creation of the button
displayButton("reactorToggle", "On", "Off", getInfo("reactorComp", "checkPower")[3], 3 + 3*percentBarLength/4 + 3, 5, 7)
----- Semi Relevant Code -----
function displayButton(name, textT, textF, state --[[T/F]], x, y, width)
buttons[name] = {active = true, xPos = x, yPos = y, width = width}
if state == true then
monitor.setBackgroundColor(colors.black)
monitor.setTextColor(colors.white)
else
monitor.setBackgroundColor(colors.red)
monitor.setTextColor(colors.white)
end
monitor.setCursorPos(x, y)
mWrite(textF..string.rep(" ", math.floor(width/2) - string.len(textF)))
monitor.setBackgroundColor(colors.black)
mWrite(" ")
if state == true then
monitor.setBackgroundColor(colors.green)
monitor.setTextColor(colors.white)
else
monitor.setBackgroundColor(colors.black)
monitor.setTextColor(colors.white)
end
mWrite(textT..string.rep(" ", width/2 - string.len(textT)))
end
Thanks in advance.