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

No9Name909's Button API

Started by no9name909, 14 March 2013 - 06:04 AM
no9name909 #1
Posted 14 March 2013 - 07:04 AM
Hello there!

This is my first API, so please be respectful.
This API makes it easier to draw and create buttons on computercraft.
Feel free to use it in any way you want!

How it works:

-- Draws a button but doesn't do anything when someone clicked on it.
button.drawButton(xCoord1, yCoord1, xCoord2, yCoord2, text, buttonColour, buttonTextColour)

-- Adds a button to the button list
button.addButton(xCoord1, yCoord1, xCoord2, yCoord2, text, buttonColour, buttonTextColour)

-- Clears the button list
button.clearButton()

-- Shows all the buttons from the button list on the computer
-- Returns the number of the button which is activated
buttonNumber = button.showComputer()

-- Shows all the buttons from the button list on a monitor
-- Returns the number of the button which is activated
buttonNumber = button.showMonitor(monitorSide)

-- Shows all the buttons from the button list on the computer
-- Reads what the user types
-- Returns the number of the button which is activated and a empty string or returns 1 and what the user typed in
buttonNumber, input = button.showComputerRead(xCoord, yCoord, textColour, buttonColour)

-- Shows all the buttons from the button list on a monitor
-- Reads what the user types
-- Returns the number of the button which is activated and a empty string or returns 1 and what the user typed in
buttonNumber, input = button.showMonitorRead(xCoord, yCoord, monitorSide, backgroundColour, textColour)

Explanation of variables:
xCoord1 = the x coordinate of the start of a button
yCoord1 = the y coordinate of the start of a button
xCoord2 = the x coordinate of the end of a button
yCoord2 = the y coordinate of the end of a button
text = the text on the button
buttonColour = the colour of the button
buttonTextColour = the colour of the text on the button
buttonNumber = the number of the button that is activated (for example 2 if the second button that you added with button.add() is activated)
monitorSide = the side where the monitor is next to the computer
input = the input that the user wrote down
xCoord = the x coordinate of the cursor position
yCoord = the y coordinate of the cursor position
backgroundColour = the background colour
textColour = the colour of the text that the user types in

How to use it:
First, add an button by typing in:

button.addButton(xCoord1, yCoord1, xCoord2, yCoord2, text, buttonColour, buttonTextColour)
Then show the button on the screen by using one of these functions:

buttonNumber = button.showComputer()
buttonNumber = button.showMonitor(monitorSide)
buttonNumber, input = button.showComputerRead(xCoord, yCoord, backGroundColour, textColour)
buttonNumber, input = button.showMonitorRead(xCoord, yCoord, text, backGroundColour, textColour)
You can also draw a button without any use:

button.drawButton(xCoord1, yCoord1, xCoord2, yCoord2, text, buttonColour, buttonTextColour)
If you want to clear the list of all the buttons that are added by button.addButton(), type in:

button.clearButton()

Installation:
Download the ButtonAPI.zip
Go to: %appdata% => .minecraft => mod => ComputerCraft.zip => lua => rom
Then open the ButtonAPI.zip and extract all the folders into here.
Start up minecraft and have fun! :D/>

!!! Important: It's possible that the API doesn't work for a lower version than 1.5, because it uses the peripheral API. !!!
Downloads:
Mediafire: http://www.mediafire...k71nw7by45k1fqj
Dropbox: https://www.dropbox....2/ButtonAPI.zip
[attachment=1062:ButtonAPI.zip]
joostlek #2
Posted 27 March 2013 - 05:15 AM
ok, i've been searching for a long time for a way for making buttons. but i quite like this but if i download it i can't open it

joostlek
theoctagon #3
Posted 07 May 2013 - 09:05 PM
I have installed this as described above, and I do see the api in-game in the /rom/apis folder. I have also restarted MC. The api is loaded at the head of the script. Whenever I call upon it, I get the following message:

'attempt to index ? (a function value)'

the script calling the api is:

buttonNumber = button.addButton(1, 1, 4, 4,"Butt1", blue, white)
buttonNumber = button.showComputer()
buttonNumber = button.showMonitor(right)

I have also tried it like this:
button.addButton(1, 1, 4, 4,"Butt1", blue, white)
buttonNumber = button.showComputer()
buttonNumber = button.showMonitor(right)

Same message returned. Always on the first line too (button.addButton) — Any ideas?
Avengera #4
Posted 17 June 2013 - 10:17 PM
.
jesusthekiller #5
Posted 19 June 2013 - 03:36 AM
P A S T E B I N

Just noted that it's not new thread but bumped by Avengera :/