メインコンテンツまでスキップ

Luaでダイアログを作る

ダイアログブロックでできることは、すべてLuaでも利用できます。ダイアログスクリプトは3つの部分で構成されます。新しいダイアログを開始し、質問を追加し、表示します。その後、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

表示されるダイアログは次のとおりです。

Farm helperのダイアログ

構成​

手順関数
新しいダイアログを開始Dialog:init()、Dialog:setTitle()、Dialog:setMessage()
質問を追加Dialog:add() と TextView、CheckBox、EditText、NumberInput、Slider、RadioGroup、TapPicker、TapListPicker、GestureRecorder
レイアウトを整えるPage、Section、Row、Column
質問を微調整showWhen、hideWhen、setHelp、setRequired、setRange、setStep、showAsDropdown
表示Dialog:show() または Dialog:showIfNeeded()
回答を読み取るDialog:getValueById()

知っておくと便利なこと​

  • 最初に Dialog:init() を呼び出します。新しい空のダイアログが開始されるため、1つのマクロで複数のダイアログを表示できます。
  • セッターは質問そのものを返すので、Slider(6, "Delay", 0, 1000):setStep(50):showWhen(1) のようにチェーンできます。
  • コンテナは先に中身を入れてから追加します。page:add(...) の後に Dialog:add(page) を呼びます。
  • 回答はIDで保存されるため、IDはマクロ内のすべての質問で重複しないようにしてください。
  • Dialog:show() は、ユーザーがキャンセルを押すとマクロを停止します。
  • 回答は show() または showIfNeeded() の後に読み取ります。