Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local buttons = {};
- local buttonX = {{},{}};
- local buttonY = {{},{}};
- local lastClicked = 1;
- function newButton(name, x, y, maxX, maxY)
- table.insert(buttons, name);
- table.insert(buttonX[1], x);
- table.insert(buttonY[1], y);
- table.insert(buttonX[2], maxX);
- table.insert(buttonY[2], maxY);
- end
- function termDetect()
- lastClicked = "none";
- event, button, x, y = os.pullEvent("mouse_click");
- --Check if in bounds of any button
- for i=1, #buttons do
- if((x >= buttonX[1][i]) and (x <= buttonX[2][i])) then
- if((y >= buttonY[1][i]) and (y <= buttonY[2][i])) then
- lastClicked = buttons[i];
- return buttons[i];
- end
- end
- end
- return "none";
- end
- function rmButton(button)
- for i=1, #buttons do
- if(buttons[i] == button) then
- table.remove(buttons, i);
- end
- end
- end
- function monDetect()
- lastClicked = "none";
- event, side, x, y = os.pullEvent("monitor_touch");
- for i=1, #buttons do
- if((x >= buttonX[1][i]) and (x <= buttonX[2][i])) then
- if((y >= buttonY[1][i]) and (y <= button[2][i])) then
- lastClicked = buttons[i];
- return buttons[i];
- end
- end
- end
- return "none";
- end
- function getLastClicked()
- return lastClicked;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement