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

auto button API

Started by guesswhat123212, 03 April 2014 - 10:09 PM
guesswhat123212 #1
Posted 04 April 2014 - 12:09 AM
heres an easy API for a touch screen it will auto place the buttons around the screen in the order you set them, including setting up multiple pages, it will auto detect and wrap the monitor to any side and open the wireless modem for sending rednet if needed.



HOW TO USE
===========
run pastebin get UYePv49v butapi

within your program

load api with
os.loadAPI("butapi")

define how many buttons you would like to have going across and high
butapi.howManyButtons(w,h) I.E butapi.howManyButtons(3,4)

setup your buttons with "buttonname" in quotes, the function you want it to run without the "()", boolen true or false for if you want the button to be on by default
butapi.setTable("button name",function,boolen) I.E. butapi.setTable("Test button",butapi.none,false)

then at the end of your program tell it to run
butapi.watchForClick()


please let me know what you think.
Edited on 05 April 2014 - 01:48 AM
Geforce Fan #2
Posted 05 April 2014 - 03:22 AM
Wow, I was expecting a 10-line program but looking through this seems pretty decent. But the post is very confusing, so clear that up.
Edit: What's with the "else end else end else end else end…"?
Edited on 05 April 2014 - 01:23 AM
guesswhat123212 #3
Posted 05 April 2014 - 03:43 AM
Wow, I was expecting a 10-line program but looking through this seems pretty decent. But the post is very confusing, so clear that up.
Edit: What's with the "else end else end else end else end…"?

yeah I sometimes dont explain things that greatly, I will start thinking of a better way to say it. as for the else ends I have quite a few if statement and spacing out the else end's help me keep track of the codes.
CometWolf #4
Posted 05 April 2014 - 11:13 AM
How does

if stuff then
  --do stuff
else
end
make more sense than just

if stuff then
  --do stuff
end
?
guesswhat123212 #5
Posted 05 April 2014 - 03:39 PM
How does

if stuff then
  --do stuff
else
end
make more sense than just

if stuff then
  --do stuff
end
?

cause a two line separation is easier to see then a one line separation, its just my preference while coding, no real impact on the code doing it either way unless you consider if I want to change it and actually give it an else now I dont have to type it (or if I forget to type it, it wont error out)
ry00000 #6
Posted 25 May 2015 - 03:18 PM
butapi is gonna be awesum, I feel it. I'm jumpin' in my Direwolf20 1.7.10 pack world to check it out right now!
funzrey #7
Posted 02 June 2015 - 12:28 AM
Good API! It is useful for things like button-relying games (for example a 2D sandbox with a world feature), I'm going to try this, Thanks for the API!