Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("button")
- -- Create 4 Buttons, 3 Testing and 1 Exit
- local testButton = button.new(2, 2, 20, 2, "Hello World!")
- local testButton2 = button.new(2, 6, 20 , 2, "Sup World!")
- local testButton3 = button.new(2, 10, 20, 2, "Nice World!")
- local exit = button.new(2, 14, 8, 2, "Exit")
- --Simple Loop Value
- local alive = true
- -- Create a Test ButtonGroup
- local testGroup = button.newButtonGroup()
- -- Simply Applies a different label to a button, adds "!"
- function textChange(btn)
- btn:setText(btn:getText().."!")
- end
- -- Adds 2 Toggleable Buttons to the ButtonGroup,
- -- the buttons MUST be toggleable. This acts like
- -- radio buttons, only one button in a button group
- -- is active at a time.
- testGroup:addButtons(testButton2, testButton3)
- -- setToFlash make the button non-toggleable. It flashes instead of
- -- activating or de-activating and fires it's actions ONCE.
- -- Adds TextChange Action to Button, add's a "!" to end of label on click.
- testButton:setToFlash()
- testButton:addAction(textChange)
- exit:setToFlash()
- exit:addAction(function() alive = false; end) -- Kill Loop on Click
- -- Use button API Methods for utility.
- -- Clear Screen and Initial Update to draw buttons
- term.clear()
- button.update()
- while alive do
- event, b, x, y = os.pullEvent("mouse_click")
- button.update(x, y) -- Pass Input X,Y to Update, Any buttons there are activated
- sleep(0.05)
- end
- term.clear()
- term.setCursorPos(1, 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement