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

[Right new help request...] [right-click-menu]

Started by Goof, 04 January 2013 - 12:57 AM
Goof #1
Posted 04 January 2013 - 01:57 AM
Hello.

im trying to make a right click menu (popup) but i cant get it to work, when trying to detect if the mouse button is Right, or Left.

Does anyone know anything about right and left click detection?

i do not find any good tutorials on this, so thats because i posted this:

EDIT: i found a new issue…
when trying to leftclick at the Settings menu, it doesnt work… but it does work when clicking on the Stop menu.

newest code:

http://pastebin.com/NkHQBmwi





code:
Spoiler


function tB(color)
   term.setBackgroundColor(color)
end
function tT(color)
   term.setTextColor(color)
end

tB(colors.lightGray)
term.clear()
local event, button, x, y = os.pullEvent("mouse_click")
   if event == "mouse_click" then
	  if button == "mouse_right" then
		 print("<Doing stuff>")
	  end
   end


thanks :)/>
Kingdaro #2
Posted 04 January 2013 - 02:00 AM
The button is a number. 1 for left click, 2 for right, 3 for middle.
remiX #3
Posted 04 January 2013 - 02:01 AM
button is 1, 2, or 3
1 is left click
2 is right
3 is middle
Goof #4
Posted 04 January 2013 - 02:07 AM
Thanks. :)/>




Look down…
Goof #5
Posted 04 January 2013 - 02:39 AM
Ehhm.. Im having another issue!


When left clicking on the "Settings", then it just doesnt work.. it only works when clicking on the "stop" menu… can you help..

Spoilerhttp://pastebin.com/NkHQBmwi


thanks
remiX #6
Posted 04 January 2013 - 03:18 AM
It's because of the if block within the second os.pullEvent()

As you can see that both the if and elseif have the same condition so the first one will always trigger.
               	 if x1 > (x+1) and x1 < (x+13) then
                        if y1 == (y+2) then                            
                            tB(colors.lightGray)
                            term.clear()
                            print("Choosen Stop")
                            sleep(3)
                            running = false
                        end                    
                    elseif x1 > (x+1) and x1 < (x+13) then
                        if y1 == (y+3) then                
                            tB(colors.lightGray)
                            term.clear()
                            print("Choosen Settings")
                            sleep(3)
                            term.setCursorPos(1,1)
                            running = false
                            shell.run("edit .setting@")
                            running = true
                            tB(colors.lightGray)
                            term.clear()
                            term.setCursorPos(1,1)
                            print("Settings Saved.")
                            sleep(2)
                        end        
                    end

This works:


               	 if x1 > (x+1) and x1 < (x+13) and y1 == y+2 then                    
                            tB(colors.lightGray)
                            term.clear()
                            print("Choosen Stop")
                            sleep(3)
                            running = false                
                    elseif x1 > (x+1) and x1 < (x+13) and y1 == y+3 then    
                            tB(colors.lightGray)
                            term.clear()
                            print("Choosen Settings")
                            sleep(3)
                            term.setCursorPos(1,1)
                            running = false
                            shell.run("edit .setting@")
                            running = true
                            tB(colors.lightGray)
                            term.clear()
                            term.setCursorPos(1,1)
                            print("Settings Saved.")
                            sleep(2)    
                    end
Goof #7
Posted 04 January 2013 - 04:15 AM
** Lol ** Thanks… how stupid could i just be there… :o/>

Now everything works fine :D/>

Thanks!