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

how do i make clickable buttons in functions?

Started by Waitdev_, 03 July 2015 - 10:52 AM
Waitdev_ #1
Posted 03 July 2015 - 12:52 PM
i want to make a function so i can add it into a program to make anything clickable, possibly using coroutines.

i tried coroutines one time, but i never got the hang of it. maybe someone who knows it can help?

so i would do something like

function clickable(text,funct)
--function
end
function funct1()
--random things here
end
function funct2()
--random things here
end
clickable("text1",funct1())
clickable("text2",funct2())
and that would do stuff .-.
Lupus590 #2
Posted 03 July 2015 - 01:41 PM
look at someones buttion API and either uses their's or use it to teach you how to make your own

Lyqyds touhpoint is a popular one.
Edited on 03 July 2015 - 11:42 AM
DannySMc #3
Posted 03 July 2015 - 02:13 PM
Nah don't use API's :P/> Make your own :P/> Check out my link to making touch screen buttons:
http://www.computercraft.info/forums2/index.php?/topic/16925-how-to-create-a-touch-screen-on-a-terminal/
Lewisk3 #4
Posted 20 July 2015 - 07:01 PM
i like doing a button table system like so,


local buttons = {
	   {name="Button Name",w=<width>,h=<height>,click = function()    
                 -- when button is clicked this code will run --
				  os.reboot()
		end}
}

function update()
		   a = {os.pullEvent()}
	
		if(a[1] == "mouse_click")then
			 for i = 1, #buttons do
				 -- insert updating code here --
			 end
		end
end

function draw()
		  for i = 1, #buttons do
			  -- insert drawing code here --
		 end
end

function dabigloop()
         draw()
	while true do
		  update()
          --]] dont put draw here because it will cause flickering instead handle screen refresh in the update method [[--
	end
end
Edited on 20 July 2015 - 05:03 PM
H4X0RZ #5
Posted 20 July 2015 - 11:28 PM
Nah don't use API's :P/> Make your own :P/> Check out my link to making touch screen buttons:
http://www.computerc...-on-a-terminal/

There is no need for making a "low level" (actually not that low level) API/script if others made it for you already. You don't have to reinvent the wheel.
DannySMc #6
Posted 20 July 2015 - 11:45 PM
Nah don't use API's :P/> Make your own :P/> Check out my link to making touch screen buttons:
http://www.computerc...-on-a-terminal/

There is no need for making a "low level" (actually not that low level) API/script if others made it for you already. You don't have to reinvent the wheel.

No there may not, but I have never been keen on using others API's and you are best learning it from step 1, instead of using APIs, thus giving you a better understanding of what is going on. otherwise you may not know how it all works.