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
-- vaguely based on a script by Putnam
local repeatUtil = require 'plugins.repeatUtil'
local repeatUtil = require 'repeatUtil'
local args = {...}
if args[1] == '-cancel' then
@ -27,6 +27,8 @@ elseif args[1] == '-help' then
print the results of the command
-printResult false
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 ...
specify the command to be run
]])
@ -38,10 +40,14 @@ local timeUnits
local i=1
local command={}
local printResult=true
local later = false
while i <= #args do
if args[i] == '-name' then
name = args[i+1]
i = i + 2
elseif args[i] == '-later' then
later = true
i = i+1
elseif args[i] == '-time' then
time = tonumber(args[i+1])
timeUnits = args[i+2]
@ -66,10 +72,26 @@ while i <= #args do
end
end
repeatUtil.scheduleEvery(name,time,timeUnits,function()
result = dfhack.run_command(table.unpack(command))
local callCommand = function()
local result = dfhack.run_command(table.unpack(command))
if printResult then
print(result)
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)