And his demo-programm: http://pastebin.com/xVmKfn2Y
Monitors are on the top. I get the Error :
demo:6: attempt to index ? (a nil value)
can someone help me ?
function fillTable()
button.setTable("Test1", test1, 10,20,3,5)
button.setTable("Test2", test2, 22,32,3,5)
button.setTable("Test3", test3, 10,20,8,10)
button.setTable("Test4", test4, 22,32,8,10)
button.screen()
end
--snip--
function test1()
button.flash("Test1")
print("Test1")
end
function test2()
button.toggleButton("Test2")
print("Test2")
end
function test3()
print("Test3")
end
function test4()
print("Test4")
end
function test1()
button.flash("Test1")
print("Test1")
end
function test2()
button.toggleButton("Test2")
print("Test2")
end
function test3()
print("Test3")
end
function test4()
print("Test4")
end
function fillTable()
button.setTable("Test1", test1, 10,20,3,5)
button.setTable("Test2", test2, 22,32,3,5)
button.setTable("Test3", test3, 10,20,8,10)
button.setTable("Test4", test4, 22,32,8,10)
button.screen()
end
Yes that is a problem, but not the problem at hand.-snip-
I think bit has said that above… But: errare humanum esse :D/>Notice that the error is on the first line in the demo program that tried to access a member of the button table. That particular error crops up when you try to index (access a table member of) a variable that doesn't contain a table reference. Common sense would then lead one to look at what might cause the variable in question to NOT contain the expected table. In this case, the obvious answer is that os.loadAPI("button") didn't return a table reference. Quod erat demonstrandum…
Actually you don't win (I'm assuming you used Q.E.D. in the form of "I win"). You just vomited a bunch of text on to the page that any newbie would not even understand, sure quite a lot on the forums can read it and understand, and I have the common sense you speak of to look at the errors and variables, but not everyone here can (actually I would hazard saying >80%). You have to understand that a lot of people on these forums do not understand how to read the error messages (or code and its documentation it seems), and do not understand the amount of useful information that can be contained in error messages, let alone understand debugging! The point of Ask a Pro is not for us to feed them answers with high level concepts or technical words (unless of course thats what they want), this just gets them coming back with more questions because they're confused, the point is for us to help them and give explanations in such a way that helps them, not confuses them more.Notice that the error is on the first line in the demo program that tried to access a member of the button table. That particular error crops up when you try to index (access a table member of) a variable that doesn't contain a table reference. Common sense would then lead one to look at what might cause the variable in question to NOT contain the expected table. In this case, the obvious answer is that os.loadAPI("button") didn't return a table reference. Quod erat demonstrandum…
How did you miss that?! It was literally the last comment on the page, I'd understand if it was like higher up and hidden by other lower ones, but how?!Don't know how I missed that post… damn.
-snip
I'm now using Lyqyd's button API
but is there a way to set the side of the redstone signal
I'm using his test-program but if i change the side how i would do it normaly it says invalid side.
program: (http://www.computercraft.info/forums2/index.php?/topic/14784-touchpoint-api/)
--# intialize a new button set on the top monitor
local t = touchpoint.new("top")
t:add( [button name], [function], [xMin], [yMin], [xMax], [yMax] )
t:add(name, func, xMin, yMin, xMax, yMax, inactiveColor, activeColor)
local function click()
print("Do you always click buttons?")
end
local t = touchpoint.new("top") -- for a monitor on top of the computer
local t:add("Click me!", click, 3, 3, 15, 5, colors.red, colors.lime) -- Adds a button
t:run() -- Runs the program
--# 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("blaze", nil, 2, 2, 14, 11, colors.red, colors.lime)
t:add("witch", nil, 16, 2, 28, 11, colors.red, colors.lime)
--# 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 "blaze" or "witch", since those are the button labels
--# toggle the button that was clicked.
t:toggleButton(p1)
--# and toggle the redstone output on the relevant side.
if p1 == "blaze" then
rs.setOutput("left", not rs.getOutput("left"))
elseif p1 == "witch" then
rs.setOutput("right", not rs.getOutput("right"))
end
end
end
--# load the touchpoint API
os.loadAPI("touchpoint")
--# intialize a new button set on the top monitor
local t = touchpoint.new("top")
--# create a helper function to toggle redstone
local function toggleSide(side)
rs.setOutput(side, not rs.getOutput(side))
end
--# create functions for button clicks
local function blazeClick()
t:toggleButton("blaze")
toggleSide("left")
end
local function witchClick()
t:toggleButton("witch")
toggleSide("right")
end
--# add two buttons
t:add("blaze", blazeClick, 2, 2, 14, 11, colors.red, colors.lime)
t:add("witch", witchClick, 16, 2, 28, 11, colors.red, colors.lime)
--# let the button API take care of the rest.
t:run()