Added functionality to repeat.lua so that you can make the thing that's repeating not happen right away.

develop
expwnent 2014-06-27 06:23:04 -04:00
parent 2827861edf
commit 9a8b1d04fa
1 changed files with 26 additions and 4 deletions

@ -4,7 +4,7 @@
-- author expwnent -- author expwnent
-- vaguely based on a script by Putnam -- vaguely based on a script by Putnam
local repeatUtil = require 'plugins.repeatUtil' local repeatUtil = require 'repeatUtil'
local args = {...} local args = {...}
if args[1] == '-cancel' then if args[1] == '-cancel' then
@ -27,6 +27,8 @@ elseif args[1] == '-help' then
print the results of the command print the results of the command
-printResult false -printResult false
suppress the results of the command suppress the results of the command
-later
make it happen later instead of now (every 5 ticks starting now vs every 5 ticks starting in 5 ticks)
-command ... -command ...
specify the command to be run specify the command to be run
]]) ]])
@ -38,10 +40,14 @@ local timeUnits
local i=1 local i=1
local command={} local command={}
local printResult=true local printResult=true
local later = false
while i <= #args do while i <= #args do
if args[i] == '-name' then if args[i] == '-name' then
name = args[i+1] name = args[i+1]
i = i + 2 i = i + 2
elseif args[i] == '-later' then
later = true
i = i+1
elseif args[i] == '-time' then elseif args[i] == '-time' then
time = tonumber(args[i+1]) time = tonumber(args[i+1])
timeUnits = args[i+2] timeUnits = args[i+2]
@ -66,10 +72,26 @@ while i <= #args do
end end
end end
repeatUtil.scheduleEvery(name,time,timeUnits,function() local callCommand = function()
result = dfhack.run_command(table.unpack(command)) local result = dfhack.run_command(table.unpack(command))
if printResult then if printResult then
print(result) print(result)
end end
end) end
local func
if later then
local didOnce
func = function()
if didOnce then
callCommand()
else
didOnce = true
end
end
else
func = callCommand
end
repeatUtil.scheduleEvery(name,time,timeUnits,func)