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

Mouse Click Api

Started by Thefdjurt, 22 September 2013 - 06:51 PM
Thefdjurt #1
Posted 22 September 2013 - 08:51 PM
So I've been off the forums for quite a while, but during that time I got better at Lua programming.

So the API has two functions.
Function 1: Get the mouse click coordinates.
Function 2: Test whether you click a certain place on the screen.

Sample code of function 1

Spoiler

function test()
  os.unloadAPI("clickAPI")
  os.loadAPI("clickAPI")

  term.clear()
  term.setCursorPos(1,1)
  print("Click Test 1")
  print(" ")
  print("Click Test 2")
  local x, y = clickAPI.click()
  if tonumber(x) > 0 and tonumber(x) < 13 then
	if tonumber(y) == 1 then
	  print("You clicked 'Click Test 1'.")
	  sleep(1.5)
	  tst()
	elseif tonumber(y) == 3 then
	  print("You clicked 'Click Test 2'.")
	  sleep(1.5)
	  tst()
	else
	  print(x.." "..y)
  end
  else
	print(x.." "..y)
	sleep(1.5)
	test()
  end
end
test()

and
Sample code of function 2

Spoiler

os.unloadAPI("clickAPI")
os.loadAPI("clickAPI")
function test2()
  term.clear()
  term.setCursorPos(1,1)
  print("Click Me")

  if clickAPI.click(1,1,8,1) then
	print("You clicked it.")
sleep(1.5)
test2()
  end
end
test2()

To get the API do:

pastebin get uiS71Xrd clickAPI
or view the code here http://pastebin.com/uiS71Xrd.

Please respond with any bugs issues or suggestion.
robotica34 #2
Posted 29 September 2013 - 06:34 AM
os.pullEvent provides mouse click coordinates, and you can check where it clicked yourself, so I call this pointless. Try doing something more useful! ;)/> Just sayin', no hate. Everyone has to start somewhere.
secret1timb7 #3
Posted 05 October 2013 - 06:27 PM
Theres anather way to do this without downloading a api but i was too lazy to find it on google so thankyou so much, now i can add a menu button to my game :D/>.
willwac #4
Posted 06 October 2013 - 05:55 PM
Well,


local event, x, y, click = os.pullEvent("mouse_click")
robotica34 #5
Posted 09 October 2013 - 06:36 AM
Well,

local event, x, y, click = os.pullEvent("mouse_click")
Actually, the line is
local event, click, x, y = os.pullEvent("mouse_click")
Also, you forgot your "".
Intruder_Emerald #6
Posted 15 October 2013 - 01:25 PM
Hi, I'm sure there lots of things like this but well done!