Jump to content

Function priority by timer


 Share

Recommended Posts

Hello, i havê been reading, and thinking.. Im on my tablet só i WLL try explain what im trying to do....

Will havê an GUI with 8 timer input that havê to set timer, but wen our if 2 our more ends at some time it havê to run 1, then outher , then outher

Timer 1, - input 5 minutes, timer 2 - input 10, timer 3 input 15, timer 4 - input 8,......

At some time,  timer 1 will end ate some time of timer 2 / then it at some time will end at some time timer 2 and 3 

How i said that wen it happpens first is 2 then 1, then outhers and if 1 is done then 1st is 3, will have more than 9 input boxes that can happen it end at some time, imagine if wen timer 1= 0 function1(), then after end funciona start countdown again, if timer 2 = 0 run function2(), then after end function2 start contdoen again, if both =0 at some time first run 1 then 2, and if wen ends 1, 2,3,4 are =0 :-( :-( :-(  im lost

This work…???

 

thank you!

 

  lod3n said:

Like this?

 

expand popup
$runNext = 1

For $i = 1 To 64 Step +1
    Select 
        
        Case $runNext = 1
            If function1() Then
                $runNext = 1
            Else
                $runNext = 2
            EndIf
            
        Case $runNext = 2
            If function2() Then
                $runNext = 2
            Else
                $runNext = 3
            EndIf
            
        Case $runNext = 3
            If function3() Then
                $runNext = 3
            Else
                $runNext = 4
            EndIf
            
        Case $runNext = 4
            If function4() Then
                $runNext = 4
            Else
                $runNext = 1
            EndIf
            
    EndSelect
Next

Func function1()
;code
EndFunc

Func function2()
;code
EndFunc

Func function3()
;code
EndFunc

Func function3()
;code
EndFunc

Thanks for time, any ideas??? 

 

Link to comment
Share on other sites

  • Moderators

Rfsvieira,

I think I understand what you want - if several timers fire simultaneously, you want them to be actioned in a specific order.

If I am right then this script shows you how you might do it by setting the required order in an array like this:

Global $aOrder[] = ["2;1" , "3;2;4;1"]

In this case, when both 1 & 2 fire they will be actioned in the order 2 then 1 - when all four timers fire they will be actioned in the order 3 then 2 then 4 then 1. Any other combination of timers (such as 1 & 3) will always be actioned in numerical order.

And here is the script which shows this happening. As posted, there are no "required orders" and $aOrder is empty - the timers always fire in numerical order. To change this, change the declaration line for $aOrder so that holds the "required orders" - then when you run the script the timers will fire in the specified order when a specified combination of timers is actioned:

#include <Array.au3>

HotKeySet("{ESC}", "_Exit")

; Set number of timers
Global $iTimer = 4
; Array to hold timers
Global $aTimer[$iTimer + 1]
; Array to hold timer limits           1  2   3   4
Global $aTimerLimit[$iTimer + 1] = [0, 5, 10, 15, 30]
; Array to hold timers firing
Global $aTimerFired[$iTimer + 1]

; First we have no "required orders" - all timers fire in numerical order
Global $aOrder[0]

; Now set specific order required when multiple timers fire simultaneously - all other combinations fire in numerical order
;Global $aOrder[] = ["2;1" , "3;2;4;1"]

; Convert "required orders" into suitable code - use powers of 2 so each required timer is unique
; Add a column for the codes
_ArrayColInsert($aOrder, 0)
For $i = 0 To UBound($aOrder) - 1
    $aSplit = StringSplit($aOrder[$i][1], ";")
    For $j = 1 To $aSplit[0]
        $aOrder[$i][0] += 2 ^ Number($aSplit[$j])
    Next
Next

; Just for interest, display final array with codes and orders
_ArrayDisplay($aOrder, "", Default, 8)

; Now start timers
For $i = 1 To $iTimer
    $aTimer[$i] = TimerInit()
Next

; Now wait for timmers to fire
$nLoopTimer = TimerInit()
ConsoleWrite("Timers started at " & @SEC & @CRLF & @CRLF) ; Just for display
While 1

    Sleep(10)

    ; Check every second to allow time for multiple timers to fire
    If TimerDiff($nLoopTimer) > 1000 Then
        ; Check each timer
        For $i = 1 To $iTimer
            If TimerDiff($aTimer[$i]) > ($aTimerLimit[$i] * 1000) Then
                ; Set flag for the timer
                $aTimerFired[$i] = True
                ; Add unique timer code to the flag
                $aTimerFired[0] += 2 ^ Number($i)
                ; Reset timer
                $aTimer[$i] = TimerInit()
            EndIf
        Next

        ; Check if one or more timers has fired
        If $aTimerFired[0] Then
            ; See if the total code matches a "required order"
            $iIndex = _ArraySearch($aOrder, $aTimerFired[0], 0, 0, 0, 0, 1, 0)
            If $iIndex = -1 Then
                ; Then fire in numerical order
                For $i = 1 To $iTimer
                    If $aTimerFired[$i] Then
                        ; Run function
                        Call("_Timer_" & $i)
                        ; Clear flag
                        $aTimerFired[$i] = False
                    EndIf
                Next
            Else
                ; Fire in "required order"
                $aSplit = StringSplit($aOrder[$iIndex][1], ";")
                For $i = 1 To $aSplit[0]
                    ; Run function
                    Call("_Timer_" & $aSplit[$i])
                    ; Clear flag
                    $aTimerFired[$aSplit[$i]] = False
                Next
            EndIf
            ; Clear master flag
            $aTimerFired[0] = 0

            ConsoleWrite(@CRLF) ; Just for display to separate firings



        EndIf
        ; Reset loop timer
        $nLoopTimer = TimerInit()

    EndIf

WEnd

Func _Timer_1()
    ConsoleWrite("Timer 1 Fired at " & @SEC & @CRLF)
EndFunc

Func _Timer_2()
    ConsoleWrite("Timer 2 Fired at " & @SEC & @CRLF)
EndFunc

Func _Timer_3()
    ConsoleWrite("Timer 3 Fired at " & @SEC & @CRLF)
EndFunc

Func _Timer_4()
    ConsoleWrite("Timer 4 Fired at "  & @SEC & @CRLF)
EndFunc

Func _Exit()
    Exit
EndFunc

I must admit to being quite pleased with that little script. I have tried to comment clearly, but please ask if you have any questions.

M23

Edited by Melba23
More elegant way to detect unique code

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hello, thanks

But i dont understand it, with raws and coluns ...

I will try use the sleep() , will conver it in minuts for the inputbox()

then wll try to do the loop, every time it ends the timing add by the user ( ex. 10  minuts) it starts the loop)

I dont know yet how i wll do the priority if 2 our more ends at same time :(

Thanks for your time

Link to comment
Share on other sites

  • Moderators

Rfsviera,

But i dont understand it

What do you not understand? Let me know which parts are causing you difficulty and I can explain in more detail.

M23 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...