Skip to content

Commit

Permalink
Update start.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
binux authored Oct 14, 2018
1 parent 910b9ea commit 7a28aa2
Showing 1 changed file with 49 additions and 5 deletions.
54 changes: 49 additions & 5 deletions static/start.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,59 @@
local localPath = scriptPath()
dofile(localPath.."stateMachine.lua")

failed = 0
while true do
if failed > 5 then
scriptExit('failed 5 times')
-- dialog
dialogInit()
local screens = {'nil'}
for i, screen in ipairs(stateMachine.screens) do
table.insert(screens, screen.name)
end

addTextView('while failed <= ')
addEditNumber('opt_failed', 5)
addTextView(' do')
newRow()
addTextView('\t\tstateMachine:goto(')
newRow()
addTextView('\t\t\t')
addSpinner('opt_state1', screens, screens[#screens >= 2 and 2 or 1])
newRow()
addTextView('\t\t\t')
addSpinner('opt_state2', screens, screens[#screens >= 3 and #screens or 1])
newRow()
addTextView('\t\t\t')
addSpinner('opt_state3', screens, 'nil')
newRow()
addTextView('\t\t\t')
addEditText('opt_states', 'nil,nil,nil')
newRow()
addTextView('\t\t)')
newRow()
addTextView('\t\twait(')
addEditNumber('opt_delay', 5)
addTextView(') -- seconds')
newRow()
addTextView('end')
dialogShow('settings')

opt_states = table.concat({opt_state1, opt_state2, opt_state3, opt_states}, ',')
local states = {}
for state in string.gmatch(opt_states, '([^,]+)') do
state = state:gsub('%s+', "")
if state ~= '' and state ~= 'nil' then
table.insert(states, state)
end
end
toast('goto(' .. table.concat(states, ", ") .. ')')

if not stateMachine:goto('__STATE_1__', '__STATE_2__', '__STATE_3__') then
failed = 0
while failed <= opt_failed do
if not stateMachine:goto(unpack(states)) then
stateMachine:debug('failed')
wait(10)
failed = failed + 1
end

failed = 0
wait(opt_delay)
end
scriptExit('failed ' .. failed .. ' times')

0 comments on commit 7a28aa2

Please sign in to comment.