This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
RainbowTech's profile picture

Direwolf20 API toggleButton Help

Started by RainbowTech, 30 December 2013 - 06:14 AM
RainbowTech #1
Posted 30 December 2013 - 07:14 AM
alright, i cant figure this out, I'm trying to use the button.toggleButton in Direwolf's api and i cant figure out how to use it as a on/off. for instance when the button gets toggled on I want it to emit a redstone signal out of the computers back, and when the button gets toggled off I want it to stop the output.

This is the code i'm using:

os.loadAPI("button")
mon = peripheral.wrap("right")
mon.clear()

function fillTable()
   button.setTable("Test", test1, 1, 10, 1, 10)
   button.screen()
end

function test1()
   button.toggleButton("Test")
   --and this is where i get stumped :/
end

function getClick()
   event,side,x,y = os.pullEvent("monitor_touch")
   button.checkxy(x,y)
end

fillTable()
while true do
getClick()
end

And here is the button API: http://pastebin.com/HRbMF1Eg

Now in the api i see: button[name]["active"] = false
But how do i call this in a different script?

Help would be greatly appreciated!

And thanks for your time!
LayZee #2
Posted 30 December 2013 - 10:20 PM
I started making a Button API a while back. It's usable, configurable and should be pretty easy to use if you are able to program. However, it's still a program as opposed to an actual API. Maybe I'll pick it up again.

Feel free to use it and let me know how to improve it:

http://pastebin.com/9LPMjuVT
RainbowTech #3
Posted 31 December 2013 - 02:00 AM
Thanks @LayZee I will definitely look into it!
LayZee #4
Posted 01 January 2014 - 11:57 AM
Let me know if you figure it out :-)

Alternatively, Lyqyd has made the Touchpoint API for adding buttons, etc.
http://www.computercraft.info/forums2/index.php?/topic/14784-touchpoint-api/
Lyqyd #5
Posted 01 January 2014 - 04:30 PM
The Touchpoint API is also designed to be easy to change over to when you've been using DW20's monstrosity of an "API". You may have better luck with it than most other APIs.
LayZee #6
Posted 01 January 2014 - 06:47 PM
I agree, it's very clear that Direwolf has not taken his time to study structured programming in any shape or form. He could start by reading the AaP Renewal Project guidelines and API tutorials :-)