Sign in to follow this  
Followers 0
jbh5000

Question Regarding Function & Nesting Execution

3 posts in this topic

#1 ·  Posted (edited)

I am new to this and need a little clarification on how the following function would execute.

Func slot1monitor() ;Monitor Slot 1 on the Screen
    
            Do  
        Sleep(500)                          
    Until PixelGetColor (1330, 180)<>0x004E98                  ;Wait until Slot 1 Pixel does not equal the default color meaning a table is open
    
    IF PixelGetColor (1330, 180)<>0x004E98 Then               ;If table is open 
            Sleep(500)                                ;Wait
            If PixelGetColor (1353, 059)<>0x000000 And PixelGetColor (1353, 059)<>0xF5F5F5  Then          ;If Seat 1 Open
            MouseClick("left", 1337, 055, 1)                                                              ;Click on the seat and sit down
            ElseIf PixelGetColor (1465, 105)<>0x000000 And PixelGetColor (1465, 105)<>0xF5F5F5  Then  ;If Seat 2 Open
            MouseClick("left", 1445, 103, 1)                                                              ;Click on the seat and sit down
            ElseIf PixelGetColor (1486, 197)<>0x000000 And PixelGetColor (1486, 197)<>0xF5F5F5  Then   ;If Seat 3 Open
            MouseClick("left", 1465, 190, 1)                                                              ;Click on the seat and sit down
            ElseIf PixelGetColor (1395, 257)<>0x000000 And PixelGetColor (1395, 257)<>0xF5F5F5  Then   ;If Seat 4 Open
            MouseClick("left", 1376, 252, 1)                                                              ;Click on the seat and sit down
            ElseIf PixelGetColor (1286, 274)<>0x000000 And PixelGetColor (1286, 274)<>0xF5F5F5  Then    ;If Seat 5 Open
            MouseClick("left", 1266, 271, 1)
            ElseIf  PixelGetColor (1167, 260)<>0x000000 And PixelGetColor (1167, 260)<>0xF5F5F5 Then   ;If Seat 6 Open
            MouseClick("left", 1148, 256, 1)
            ElseIf  PixelGetColor (1083, 197)<>0x000000 And PixelGetColor (1083, 197)<>0xF5F5F5 Then   ;If Seat 7 Open
            MouseClick("left", 1060, 190, 1)
            ElseIf  PixelGetColor (1097, 103)<>0x000000 And PixelGetColor (1097, 103)<>0xF5F5F5 Then   ;If Seat 8 Open
            MouseClick("left", 1081, 100, 1)                                                                    ElseIf  PixelGetColor (1210, 060)<>0x000000 And PixelGetColor (1210, 060)<>0xF5F5F5 Then   ;If Seat 9 Open
            MouseClick("left", 1191, 054, 1)
            EndIf       
            Sleep (500)
            
            If  PixelGetColor (1380, 300)=0xFFFFFF Then                             
            MouseClick("left", 1225, 308, 1)
            ElseIF PixelGetColor (0, 0)=0x000000 Then ; add seat taken popup coordinates once determined for each table.
            MouseClick("left", 0, 0, 1)     ;seat taken popup close click on OK button
            Else 
            MouseClick("left", 1488, -22, 1)    
            EndIf   
            
    EndIf
        
            Sleep (5000)
            table1sitoutconfirm()
            
            
        
EndFunc

I would like to confirm that the Do /Sleep/Until function will basically pause any of the rest of the function from executing for as long as the condition is true and will just sit there and wait until the pixel color changes.

After that the rest of the script would execute correct?

The reason I ask is because I am running 12 of these for 12 slots on the screen, and only 4 out of 12 seem to be working.

It may be a nesting issue with the rest of them, but I wanted to ask someone who knows more to see if I dont understand the function correctly and the rest of the script may be executing before it should.

Edited by jbh5000

Share this post


Link to post
Share on other sites



After more testing I have determined that there is a problem with the nesting in my loop. See code below.

While 1=1


    While  countopentables()<$numberoftables
    setopentables() 
    If $slot1=0 Then
    slot1monitor()
    EndIf
    If $slot2=0 Then
    slot2monitor()
    EndIf
    If $slot3=0 Then
    slot3monitor()
    EndIf
    If $slot4=0 Then
    slot4monitor()
    EndIf
    If $slot5=0 Then
    slot5monitor()
    EndIf
    If $slot6=0 Then
    slot6monitor()
    EndIf
    If $slot7=0 Then
    slot7monitor()
    EndIf
    If $slot8=0 Then
    slot8monitor()
    EndIf
    If $slot9=0 Then
    slot9monitor()
    EndIf
    If $slot10=0 Then
    slot10monitor()
    EndIf
    If $slot11=0 Then
    slot11monitor()
    EndIf
    If $slot12=0 Then
    slot12monitor() 
    EndIf
        opentable()
    Sleep (8000)
WEnd

This is basically a loop of 12 functions monitoring the 12 slots on the screen.

All Of them start with a Do/Until Function to sleep until a pixel color is changed.

However, function 2 will not start unless function 1 has been triggered and function 3 wont start unless function 2 has been triggered.

Is there a way to have these 12 functions start monitoring at the same time instead of waiting for the previous function to complete?

Thanks in advance

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Is there a way to have these 12 functions start monitoring at the same time instead of waiting for the previous function to complete?

Thanks in advance

It depends on what the functions slot1monitor() to slot12monitor() do.

The way your script is arranged at the moment the functions will all appear to operate at the same time if the slotmonitor functions return quickly, so if the pixel colour is not correct why not return immediately rather than sleep and it will get checked again the next time round.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
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
Sign in to follow this  
Followers 0