Dialogs in Lua
Everything the dialog blocks do is available in Lua. A dialog script has three parts: start a new dialog, add the questions, show it. Then read the answers by id.
Dialog:init()
Dialog:setTitle("Farm helper")
Dialog:add(TextView("Set it up once. You can change it later."))
Dialog:add(CheckBox(1, "Collect daily rewards", true))
Dialog:add(NumberInput(2, "Runs", 10):setRange(1, 999))
local mode = RadioGroup(3, 1)
mode:add(RadioButton(1, "Farm"))
mode:add(RadioButton(2, "Arena"))
Dialog:add(mode)
Dialog:add(TapPicker(4, "Tap the Attack button"):showWhen(3, 2))
Dialog:add(GestureRecorder(5, "Play your route once"))
local advanced = Section("Advanced", true)
advanced:add(Slider(6, "Delay (ms)", 0, 1000, 300):setStep(50):setHelp("Wait between actions"))
Dialog:add(advanced)
Dialog:showIfNeeded()
local runs = Dialog:getValueById(2)
local delay = Dialog:getValueById(6)
for i = 1, runs do
if Dialog:getValueById(3) == 2 then
Screen:click(Dialog:getValueById(4), ClickParams())
end
Record:play(Dialog:getValueById(5))
sleep(delay)
end
This is the dialog it shows:
The parts
| Step | Functions |
|---|---|
| Start a new dialog | Dialog:init(), Dialog:setTitle(), Dialog:setMessage() |
| Add questions | Dialog:add() with TextView, CheckBox, EditText, NumberInput, Slider, RadioGroup, TapPicker, TapListPicker, GestureRecorder |
| Arrange them | Page, Section, Row, Column |
| Fine-tune a question | showWhen, hideWhen, setHelp, setRequired, setRange, setStep, showAsDropdown |
| Show it | Dialog:show() or Dialog:showIfNeeded() |
| Read the answers | Dialog:getValueById() |
Good to know
- Call
Dialog:init()first. It starts a new, empty dialog, so a macro can show more than one. - The setters return the question, so they chain:
Slider(6, "Delay", 0, 1000):setStep(50):showWhen(1). - Containers are filled first and added after:
page:add(...), thenDialog:add(page). - Ids must be different for every question in the macro, because answers are saved by id.
Dialog:show()stops the macro if the user presses Cancel.- Read answers after
show()orshowIfNeeded().