[Question] Mouse clicks!
Started by Stormkrow, Nov 13 2012 06:20 PM
9 replies to this topic
#1
Posted 13 November 2012 - 06:20 PM
Hi all,
Just playing with the new Mouse Capabilities and i wanna make a type of button, there are some helpful tutorials showing how it all works. But my problem is that they set the conditions so that only if you click on the first character of the option or button then the action takes place.
Is there a way to maybe store the co ords in an array or something so have a that i can click anywhere on the button and not a single specific character?
Thanks!
Just playing with the new Mouse Capabilities and i wanna make a type of button, there are some helpful tutorials showing how it all works. But my problem is that they set the conditions so that only if you click on the first character of the option or button then the action takes place.
Is there a way to maybe store the co ords in an array or something so have a that i can click anywhere on the button and not a single specific character?
Thanks!
#2
Posted 13 November 2012 - 06:42 PM
event, button, mouseX, mouseY = os.pullEvent("mouse_click") --Registers mouse click
if button == 1 then --if the left mouse button was used
if mouseY == YofOption and mouseX < X1afterOption and mouseX > X1beforeOption then --if the Y co-ord of the mouse is the Y that the button was on, and the X of the mouse is in a smaller co-ord than one X after the button and a larger co-odrd than one X before the button then do...
--put stuff here
end
end
That should fix it. Sorry if it's a bit complicated, I tried to explain it.
#3
Posted 13 November 2012 - 06:59 PM
Here is a function I made a while back:
function buttonMenu(table)
while running do
term.clear()
for k,v in ipairs(table) do
if table[k].buttonVisible then
term.setCursorPos(table[k].buttonStartX, table[k].buttonStartY)
print(table[k].buttonText)
end
end
event, buttonType, x, y = os.pullEvent("mouse_click")
for k,v in ipairs(table) do
if buttonType == table[k].buttonType and table[k].buttonVisible then
if x >= table[k].buttonStartX and x <= table[k].buttonEndX and y >= table[k].buttonStartY and y <= table[k].buttonEndY then
table[k].buttonFunction()
end
end
end
end
term.clear()
term.setCursorPos(1,1)
end
Here is the LINK to a example program I made with it. Just use the same vars as in the table and change the values.
#4
Posted 13 November 2012 - 07:06 PM
Shnupbups100, on 13 November 2012 - 06:42 PM, said:
event, button, mouseX, mouseY = os.pullEvent("mouse_click") --Registers mouse click
if button == 1 then --if the left mouse button was used
if mouseY == YofOption and mouseX < X1afterOption and mouseX > X1beforeOption then --if the Y co-ord of the mouse is the Y that the button was on, and the X of the mouse is in a smaller co-ord than one X after the button and a larger co-odrd than one X before the button then do...
--put stuff here
end
end
That should fix it. Sorry if it's a bit complicated, I tried to explain it.local event, button, xPos, yPos = os.pullEvent("mouse_click")
if button == 1 then
if (xPos => 1 and xPos <= 6 and yPos =>1 and yPos =< 6) then
--Put stuff here
end
end
Here you're saying, check what button is clicked, if it's left button then check if the cursor is inside the X and Y coords, if it is in those coords do stuff.You can define your stuff in a function to make this part less crowded
#5
Posted 13 November 2012 - 07:10 PM
Ooooohhh thanks guys!!! ^^
#8
#9
Posted 13 November 2012 - 07:18 PM
Human, on 13 November 2012 - 07:15 PM, said:
True, but we don't need many things here, at least for now so the 4 lines code should work like a charm
#10
Posted 13 November 2012 - 07:55 PM
Heracles421, on 13 November 2012 - 07:18 PM, said:
Human, on 13 November 2012 - 07:15 PM, said:
True, but we don't need many things here, at least for now so the 4 lines code should work like a charm
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











