[CMD] Sleep

stable
By Strooth in Miscellaneous Published May 2021 👁 1,424 views 💬 2 comments

Description

Simple command to sleep/pause scripts and includes a switch to disable in backtest. To sleep for 10 seconds for example CC_Sleep(10) Requires custom command Mod -- Author - Strooth - Find me on discord - strooth#4739 -- Feel free to donate to support my work or if my script helped you in any way <3 -- BTC Adress: 33MsEAbA8tg7SpohgnCpSrmPTBih2UkhxQ --
HaasScript
-- Author - Strooth - Find me on discord - strooth#4739
-- Feel free to donate to support my work or if my script helped you in any way &lt;3
-- BTC Adress: 33MsEAbA8tg7SpohgnCpSrmPTBih2UkhxQ
--
local name = 'Sleep'
DefineCommand(name, 'Stops a script for n seconds')
local input  = DefineParameter(NumberType, 'seconds', 'The n seconds to sleep', true, 1)
local log  = DefineParameter(BooleanType, 'log', 'Show a log', false, false)
local test  = DefineParameter(BooleanType, 'backtest', 'skip if backtesting', false, false)
local function createCountdownTimer(second)
    second = IfNull(second,1) == 0 and 1 or IfNull(second,1)
    local ms = second * 1000  
    local function countDown()
        ms = ms -1
        return ms
    end
    return countDown
end
local sleep = function (s, l, t)
    if IsFalse(t) then 
        local timer = createCountdownTimer(s) 
        local count = 0 
        repeat 
            count = timer()        
            if IsTrue(l) then 
                if CC_mod(count, 1000) == 0 then 
                    Log('['..name..'] '..s-(count/1000)..' seconds remaining')
                end 
            end 
        until count == 0
        return count == 0 
    else 
        return true 
    end 
end 
DefineOutput(BooleanType, sleep(input, log, test), 'Slept', 'true')

2 Comments

Sign in to leave a comment.

D
dubse almost 5 years ago

Hey strooth,

thanks for the script.
But there is a little bug in it - the function "GetTimer" returns the elapsed time in milliseconds.

S
Strooth over 4 years ago

Just added a new revision