Trouble With Buttons Again
#1
Posted 18 September 2013 - 12:10 PM
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 ?
#2
Posted 18 September 2013 - 12:49 PM
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
should be:
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
What you should really do is start using other people button apis. I have heard that Direwolf20's ButtonAPI is buggy, hard to use, etc. Try Lyqyd's button API. I think it's a good, easy to use API.
Edited by MKlegoman357, 18 September 2013 - 12:58 PM.
#3
Posted 18 September 2013 - 01:03 PM
MKlegoman357, on 18 September 2013 - 12:49 PM, said:
The error that occurs is that the table button does not exist when attempting to call button.setTable. The reason this error is occurring is most likely because OP has failed to save direwolf's API into a file called `button`. When calling os.loadAPI("button") on line 1 this is getting the file `button` and loading it into a table `button`, you're missing step 1, the file named `button`.
#4
Posted 18 September 2013 - 01:48 PM
#5
Posted 18 September 2013 - 03:14 PM
#6
Posted 18 September 2013 - 03:19 PM
BigTwisty, on 18 September 2013 - 03:14 PM, said:
#7
Posted 18 September 2013 - 03:32 PM
#8
Posted 18 September 2013 - 03:39 PM
BigTwisty, on 18 September 2013 - 03:14 PM, said:
EDIT:
BigTwisty, on 18 September 2013 - 03:32 PM, said:
Edited by theoriginalbit, 18 September 2013 - 03:46 PM.
#9
Posted 19 September 2013 - 12:25 PM
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.computerc...touchpoint-api/)
#10
Posted 19 September 2013 - 01:30 PM
theoriginalbit, on 18 September 2013 - 03:39 PM, said:
- Q.E.D. doesn't mean "I win." It means "that which was to be demonstrated." I wasn't aware this was a contest.
- The OP said he didn't realize that error could occur because of this, so I tried to walk him through the logical process of bug hunting, which is a difficult skill to learn. I'm sorry you see that as "vomit".
- How did I miss it? It was not the last post on the page. Even so, when skimming through the thread, all I saw was "Yes that is a problem, but not the problem at hand." For some reason my visual filters removed the whole next paragraph, and I didn't want the OP left hanging. Mistakes happen, and I already apologized for this one. There's no need to be a douche nozzle about it.
#11
Posted 19 September 2013 - 02:12 PM
Alexander0507, on 19 September 2013 - 12:25 PM, said:
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.computerc...touchpoint-api/)
The example program uses the names of the buttons as the sides. To use other names, you simply add an if tree to check the name given in the event and control the relevant output sides. If that doesn't make sense, I can provide some example code later.
#12
Posted 19 September 2013 - 02:29 PM
@Alex: Are you talking about the line where you set the side for the monitor?
--# intialize a new button set on the top monitor
local t = touchpoint.new("top")
If so, are you surrounding the side string with quotes? Are you pointing at a valid side? With all the possibilities, it would help if we could see your code.
#13
Posted 20 September 2013 - 08:05 AM
(sorry i'm not the best
#14
Posted 20 September 2013 - 09:13 AM
t:add( [button name], [function], [xMin], [yMin], [xMax], [yMax] )
The first parameter in t:add is the button name. The second is the function you want called when you click on the button.
#15
Posted 20 September 2013 - 09:20 AM
t:add(name, func, xMin, yMin, xMax, yMax, inactiveColor, activeColor)
The first parameter in t:add is the name (and the displayed text) for the button. The second is the function you want to run when the user clicks the button.
Example:
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
#16
Posted 20 September 2013 - 12:24 PM
--# 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
Or, if you wanted to use :run() instead, it's pretty easy still:
--# 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()
#17
Posted 20 September 2013 - 04:55 PM
#18
Posted 20 September 2013 - 08:05 PM
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











