At6nmKpK thats code so far, as of now the buttons are toggleable on the screen; however it doesn't actually control the redstone signal.
Any help will be greatly appreciated :)/>
To start off, it's worth bearing in mind that under ComputerCraft 1.6, bundled cables are effectively unusable at present. You're not using the redstone bundled cable functions, but you are referring to colours later in the script, so I'm assuming that's your intention?
Your button names are not valid output sides. Those consist of directions relative to your computer's facing - "back", "forward", "left", etc.
I'm pretty sure you're going to have to define your grinder/spawner/etc functions before you try to build buttons out of them.
--# load the touchpoint API
os.loadAPI("touchpoint")
--# intialize a new button set on the top monitor
local t = touchpoint.new("top")
function grinder()
rsOut[colors.white] = not rsOut[colors.white]
end
function spawner()
rsOut[colors.lime] = not rsOut[colors.lime]
end
function melter()
rsOut[colors.red] = not rsOut[colors.red]
end
function lights()
rsOut[colors.cyan] = not rsOut[colors.cyan]
end
function doors()
rsOut[colors.purple] = not rsOut[colors.purple]
end
--# add two buttons
t:add("Grinder", grinder, 2, 2, 9, 4, colors.red, colors.cyan)
t:add("Spawner", spawner,11 ,2,19, 4, colors.red, colors.cyan)
t:add("Melter", melter,21, 2,29, 4, colors.red, colors.cyan)
t:add("Lights", lights,31, 2,39, 4, colors.red, colors.cyan)
t:add("Doors", doors,41, 2,49, 4, colors.red, colors.cyan)
--# draw the buttons
t:draw()
while true do
--# handleEvents will convert monitor_touch events to button_click if it was on a button
local event, p1 = t:handleEvents(os.pullEvent())
if event == "button_click" then
--# p1 will be "left" or "right", since those are the button labels
--# toggle the button that was clicked.
t:toggleButton(p1)
--# and toggle the redstone output on that side.
--# rs.setOutput(p1, not rs.getOutput(p1))
end
end
t.buttonList[p1].func()
After the t:togglebutton, throw in a:t.buttonList[p1].func()
That will actually call the function you've assigned to each button.
Of course, you still need to correct those functions to actually do what you want, but that will at least get the functions being called.
Spoiler
rsOut[whatever] isn't correct, I've never seen anyone try to use that for output before. You'd need rs.setBundledOutput(color). If you're using CC 1.57 or CC 1.58, the MFR bundled cables should work, but if you're on CC 1.6+, there aren't any compatible bundled cables that I know of.
What line is the <name> expected error on?
t.buttonList[p1].func()
--# load the touchpoint API
os.loadAPI("touchpoint")
--# intialize a new button set on the top monitor
local t = touchpoint.new("top")
--# add two buttons
t:add("Grinder", grinder, 2, 2, 9, 4, colors.red, colors.cyan)
t:add("Spawner", spawner,11 ,2,19, 4, colors.red, colors.cyan)
t:add("Melter", melter,21, 2,29, 4, colors.red, colors.cyan)
t:add("Lights", lights,31, 2,39, 4, colors.red, colors.cyan)
t:add("Doors", doors,41, 2,49, 4, colors.red, colors.cyan)
--# draw the buttons
t:draw()
while true do
--# handleEvents will convert monitor_touch events to button_click if it was on a button
local event, p1 = t:handleEvents(os.pullEvent())
if event == "button_click" then
--# p1 will be "left" or "right", since those are the button labels
--# toggle the button that was clicked.
t:toggleButton(p1)
t.buttonList[p1].func()
--# and toggle the redstone output on that side.
--# rs.setOutput(p1, not rs.getOutput(p1))
end
end
function grinder()
rsOut[colors.white] = not rsOut[colors.white]
end
function spawner()
rsOut[colors.lime] = not rsOut[colors.lime]
end
function melter()
rsOut[colors.red] = not rsOut[colors.red]
end
function lights()
rsOut[colors.cyan] = not rsOut[colors.cyan]
end
function doors()
rsOut[colors.purple] = not rsOut[colors.purple]
end
rs.setBundledOutput("back", (colors.test(rs.getBundledOutput("back"), colors.black) and colors.subtract(rs.getBundledOutput("back"), colors.black) or colors.combine(rs.getBundledOutput("back"), colors.black)))
rs.setBundledOutput("back", (colors.test(rs.getBundledOutput("back"), colors.black) and colors.subtract(rs.getBundledOutput("back"), colors.black) or colors.combine(rs.getBundledOutput("back"), colors.black)))
local function toggleBundledColor(side, color)
rs.setBundledOutput(side, (colors.test(rs.getBundledOutput(side), color) and colors.subtract(rs.getBundledOutput(side), color) or colors.combine(rs.getBundledOutput(side), color)))
end
local function grinder()
toggleBundledColor("back", colors.white)
end
t:add("Grinder", grinder, 2, 2, 9, 4, colors.red, colors.cyan)
--# load the touchpoint API
os.loadAPI("touchpoint")
--# intialize a new button set on the top monitor
local t = touchpoint.new("top")
local function toggleBundledColor(side, color)
rs.setBundledOutput(side, (colors.test(rs.getBundledOutput(side), color) and colors.subtract(rs.getBundledOutput(side), color) or colors.combine(rs.getBundledOutput(side), color)))
end
local function grinder()
toggleBundledColors("back", colors.white)
end
local function spawner()
toggleBundledColors("back", colors.lime)
end
local function melter()
toggleBundledColors("back", colors.red)
end
local function lights()
toggleBundledColors("back", colors.cyan)
end
local function doors()
toggleBundledColor("back", colors.purple)
end
--# add two buttons
t:add("Grinder", grinder, 2, 2, 9, 4, colors.red, colors.cyan)
t:add("Spawner", spawner,11 ,2,19, 4, colors.red, colors.cyan)
t:add("Melter", melter,21, 2,29, 4, colors.red, colors.cyan)
t:add("Lights", lights,31, 2,39, 4, colors.red, colors.cyan)
t:add("Doors", doors,41, 2,49, 4, colors.red, colors.cyan)
--# draw the buttons
t:draw()
while true do
--# handleEvents will convert monitor_touch events to button_click if it was on a button
local event, p1 = t:handleEvents(os.pullEvent())
if event == "button_click" then
--# p1 will be "left" or "right", since those are the button labels
--# toggle the button that was clicked.
t:toggleButton(p1)
--# and toggle the redstone output on that side.
--# rs.setOutput(p1, not rs.getOutput(p1))
end
end
--# load the touchpoint API
os.loadAPI("touchpoint")
--# intialize a new button set on the top monitor
local t = touchpoint.new("top")
local function toggleBundledColor(side, color)
rs.setBundledOutput(side, (colors.test(rs.getBundledOutput(side), color) and colors.subtract(rs.getBundledOutput(side), color) or colors.combine(rs.getBundledOutput(side), color)))
end
local function grinder()
toggleBundledColors("back", colors.white)
end
local function spawner()
toggleBundledColors("back", colors.lime)
end
local function melter()
toggleBundledColors("back", colors.red)
end
local function lights()
toggleBundledColors("back", colors.cyan)
end
local function doors()
toggleBundledColor("back", colors.purple)
end
--# add two buttons
t:add("Grinder", grinder, 2, 2, 9, 4, colors.red, colors.cyan)
t:add("Spawner", spawner,11 ,2,19, 4, colors.red, colors.cyan)
t:add("Melter", melter,21, 2,29, 4, colors.red, colors.cyan)
t:add("Lights", lights,31, 2,39, 4, colors.red, colors.cyan)
t:add("Doors", doors,41, 2,49, 4, colors.red, colors.cyan)
--# draw the buttons
t:draw()
while true do
--# handleEvents will convert monitor_touch events to button_click if it was on a button
local event, p1 = t:handleEvents(os.pullEvent())
if event == "button_click" then
--# p1 will be "left" or "right", since those are the button labels
--# toggle the button that was clicked.
t:toggleButton(p1)
print(p1)
t.buttonList[p1].func()
--# and toggle the redstone output on that side.
--# rs.setOutput(p1, not rs.getOutput(p1))
end
end
local function grinder()
toggleBundledColors("back", colors.white)
end
should be
local function grinder()
toggleBundledColor("back", colors.white)
end
for spawner(), melter(), and lights() as well. That's what got you nil as toggleBundledColors() is not a defined function, but toggleBundledColor() is.