Advertisement
Dlog_M125

redstonefarm

Mar 29th, 2024
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.61 KB | Source Code | 0 0
  1. -- Define the positions and sizes of the buttons
  2. local leftButton = {x = 5, y = 5, width = 10, height = 3}
  3. local rightButton = {x = 20, y = 5, width = 10, height = 3}
  4.  
  5. -- Function to draw a button
  6. local function drawButton(button, label, bgColor, textColor)
  7.     term.setBackgroundColor(bgColor)
  8.     term.setTextColor(textColor)
  9.     term.setCursorPos(button.x, button.y)
  10.     term.clearLine()
  11.     term.setCursorPos(button.x + math.floor((button.width - #label) / 2), button.y + math.floor(button.height / 2))
  12.     term.write(label)
  13. end
  14.  
  15. -- Function to check if a point is within a button
  16. local function isWithinButton(button, x, y)
  17.     return x >= button.x and x < button.x + button.width and y >= button.y and y < button.y + button.height
  18. end
  19.  
  20. -- Function to handle button clicks
  21. local function handleButtonClick(x, y)
  22.     if isWithinButton(leftButton, x, y) then
  23.         redstone.setOutput("left", true)
  24.         sleep(0.5)
  25.         redstone.setOutput("left", false)
  26.     elseif isWithinButton(rightButton, x, y) then
  27.         redstone.setOutput("right", true)
  28.         sleep(0.5)
  29.         redstone.setOutput("right", false)
  30.     end
  31. end
  32.  
  33. -- Main function to draw buttons and handle input
  34. local function main()
  35.     term.clear()
  36.     term.setCursorPos(1, 1)
  37.     term.write("Click the buttons to send redstone signals:")
  38.     drawButton(leftButton, "Left", colors.blue, colors.white)
  39.     drawButton(rightButton, "Right", colors.green, colors.white)
  40.  
  41.     while true do
  42.         local event, button, x, y = os.pullEvent("monitor_touch")
  43.         handleButtonClick(x, y)
  44.     end
  45. end
  46.  
  47. -- Run the main function
  48. main()
  49.  
Tags: cc:tweaked
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement