0

Timer wildcard problems

Is it possible to use wildcards (-1), for every entry in a timer, so that it would trigger every second?

I tried:

m.timer.SetTime(-1,-1,-1)
m.timer.start()

and:

m.timer.SetTime(-1,-1,-1,0)
m.timer.start()

 Both didn't trigger any event, when I use:

m.timer.SetTime(-1,-1,0)
m.timer.start()

 it triggers every minute.

I have a workaround but it is a little bit unhandy, because I have to call the function with each triggered event.

function increaseTimer()
        currentTime = m.systemTime.GetLocalDateTime()
        currentTime.addSeconds(1)
        currentTime.setMillisecond(0)
        
        m.timer.SetDateTime(currentTime)
        m.timer.start()
end function

7 comments

  • 0
    Avatar
    Bright Scripters

    You could use a BrightAuthor timeout event set to 1, and if you need to execute some Brightscript code at that interval, you could send a plugin message from the BrightAuthor event.

    If you want to keep everything in the plugin, you could set a timer for 1000ms, and when its event is captured, trigger the same timer again.

     

    We are looking for Bright Scripters such as yourself, and would be happy to chat offline, and get to know you.

    If you find that interesting, please email info@brightscripters.com

     

  • 0
    Avatar
    Lukas Uebachs

    Because I have a clock and a count down on screen I want the event to trigger on the whole second to have synchronus change on clock and countdown.

    The workaround does the job, found nothing in documentation, that pure wildcard would result in no event triggered.

  • 0
    Avatar
    Bright Scripters

    Thanks for sharing your results!

     

    Wonder what would happen if you tried a non zero value:

    m.timer.SetTime(-1,-1,-1,999)

    or

    m.timer.SetTime(-1,-1,-1,1)

  • 0
    Avatar
    Lukas Uebachs

    Already tried with -1,-1,-1,500 no result too

  • 0
    Avatar
    Bright Scripters

    This could be a bug worth reporting...

    With that said, this could have been put in place by design, to protect us from generating events every 1ms and bring the player down to its knees... :)

  • 0
    Avatar
    Lukas Uebachs

    So this is the final result, sends plugin message on each full hour, and change user variables CountMinutes; CountSecs:

    function countdown_Initialize(msgPort as Object, userVariables as Object, bsp as Object)

        print "countdown_Initialize - entry"
        print "type of msgPort is ";type(msgPort)
        print "type of userVariables is ";type(userVariables)

        countdownBuilder = newCountdownBuilder(msgPort, userVariables, bsp)

        return countdownBuilder
     
    end function
     
    function newCountdownBuilder(msgPort as Object, userVariables as Object, bsp as Object)

        'store global variables
        CountdownBuilder                = { }
        CountdownBuilder.objectName     = "countdown_object"
        CountdownBuilder.msgPort        = msgPort
        CountdownBuilder.bsp            = bsp
        CountdownBuilder.userVariables    = userVariables
        CountdownBuilder.ProcessEvent     = countdown_ProcessEvent
        
        'register timer objects
        CountdownBuilder.systemTime        = CreateObject( "roSystemTime")
        CountdownBuilder.timer            = CreateObject("roTimer")
        CountdownBuilder.timer.setPort( CountdownBuilder.msgPort)
        
        'register functions
        CountdownBuilder.increaseTimer    = increaseTimer
        CountdownBuilder.endCountdown    = endCountdown
        
        if CountdownBuilder.systemTime.isValid() then
            CountdownBuilder.increaseTimer()
        else
            CountdownBuilder.userVariables.CountMinutes.setCurrentValue( "xx", true)
            CountdownBuilder.userVariables.CountSecs.setCurrentValue( "xx", true)
        endif
        
        return CountdownBuilder
         
    end function

    function increaseTimer()
            currentTime = m.systemTime.GetLocalDateTime()
            currentTime.addSeconds(1)
            currentTime.setMillisecond(0)
            
            m.timer.SetDateTime(currentTime)
            m.timer.start()
    end function
     
    function countdown_ProcessEvent(event as Object)
     
    '    print "type of m is ";type(m)
    '    print "type of event is ";type(event)
        
        if type(event)= "roTimerEvent" then
            
            'check identity to avoid trigger by timeout in presentation
            timerIdentity    = event.getSourceIdentity()
            
            if m.timer.getIdentity() = timerIdentity then
            
                nominutesleft = false
                if m.systemTime.isValid() then
                    m.increaseTimer()
                
                    now     = m.systemTime.GetLocalDateTime()
                    
                    minutes = now.GetMinute()
                    seconds = now.GetSecond()
                    
                    'change this condition if more than once per hour
                    if minutes > 0 then
                        minutes = 60 - minutes
                    else
                        print "NO Minutes left"
                        nominutesleft = true
                    endif
                    
                    if seconds > 0 then
                        seconds = 60 - seconds
                    else
                        seconds = 0
                        if nominutesleft then
                            print "endCountdown"
                            endCountdown(m)
                        endif
                    endif
                    
                    minutesStr$ = minutes.ToStr()
                    if minutes < 10 then
                        minutesStr$ = "0"+minutesStr$
                    endif
                    
                    secStr$ = seconds.ToStr()
                    if seconds < 10 then
                        secStr$ = "0"+secStr$
                    endif
                    
                    m.userVariables.CountMinutes.setCurrentValue( minutesStr$, true)
                    m.userVariables.CountSecs.setCurrentValue( secStr$, true)

                endif
                
            endif
            
            return false
        else
            return false
        endif

    end function

    function endCountdown(counter as Object)
        pluginMessageCmd = CreateObject("roAssociativeArray")
        pluginMessageCmd["EventType"] = "EVENT_PLUGIN_MESSAGE"
        pluginMessageCmd["PluginName"] = "countdown"
        pluginMessageCmd["PluginMessage"] = "end"
        counter.msgPort.PostMessage(pluginMessageCmd)
    end function

    P.S: Code Tags would be nice in the

  • 0
    Avatar
    Bright Scripters

    You are the real deal :)

    Thanks for sharing

Please sign in to leave a comment.