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

Buttons?

Started by Krul__Tepes, 23 July 2017 - 10:27 AM
Krul__Tepes #1
Posted 23 July 2017 - 12:27 PM
im trying to make buttons for my phone program to launch apps all i have for it is a border around the screen
how would i add buttons to launch programs to it?
danielsv03 #2
Posted 23 July 2017 - 01:15 PM
it depends if you want gui buttons, you could use many different ways of this but one way is to do ex: paintutils.drawFilledBox(1, 1, 10, 19, colors.gray)
and from there you want an mouse click detection and mouse click position

ex:


function click() --this function is for checking where and if clicked
    event, button, x, y = os.pullEvent("mouse_click") --this will call the event with the variables button, x, y
    if button == 1 then --if user click left click  (2 is for right click and 3 is for middle click)
        if x>=34 and x<= 45 and y == 3 then --check if x is more or equal to 34 and less or equal too 45 and Y is equal to 3 thats gonna be the area  where the button is
       shell.run("program to run here") --runs the program
       end
    end
end
Edited on 23 July 2017 - 11:17 AM
KingofGamesYami #3
Posted 23 July 2017 - 01:16 PM
The easiest way would be to use a button API such as touchpoint.
Krul__Tepes #4
Posted 23 July 2017 - 06:24 PM
both these replies confuse me xD

well Danels makes sense but the 4th line
KingofGamesYami #5
Posted 23 July 2017 - 06:28 PM
If you have anything specific you'd like more information on, I'd be happy to oblige. Here's a tutorial which may answer some of your questions.
danielsv03 #6
Posted 24 July 2017 - 09:21 AM
both these replies confuse me xD

well Danels makes sense but the 4th line
okay so the 4th line is to tell the program where it should accept the click/where the button area is
a good way to do this is too tell it first: if x is more or equal to example 34 and x is less or equal too 50 this will keep it in between 34 and 50 as x
picture: —–>34 between 50<—–

and lastly the Y it tells if the y is ex on line 3 then continue if all those is correct.
Note: you can do the same with Y as with x

I tried to do my best explaining just ask if you have any questions :)/>