Warriorfoe

Nesting If then Statements

4 posts in this topic

#1 ·  Posted (edited)

Okay so here's the problem.

I have a script I'm testing out where I want it to search for a certain color and if it finds that certain color I want it to check for a second color. I only want it to check for the second color after checking for the first color. If it finds the first color it will check for the second color and whether or not that second color is present it will cause certain actions to be undertaken. Well at least that's what I want it to do. I want this all to be done in a loop where it's constantly checking for the first color. However, once it does find the first color and it executes one of the actions regarding the second, I want the program to quit. I'm having trouble figuring out how to nest conditional statements here. If anyone could help me out it would be much appreciated.

HotKeySet("{ESC}", "Terminate")
HotKeySet("!c", "getColor")
HotKeySet("!l", "ClickPositions")
Global $color
Global $interval

$interval = "10000"
MsgBox (0, "Starting Up", "Starting, use ESC to quit, Alt + C to get color, and Alt + L to begin Test")

Func Terminate()
Exit 1
EndFunc
Func ClickPositions()
   MsgBox(0, "Beginning Test", "Hope to god this works")
   While 1
      $Coords = PixelSearch(1006, 48, 1074, 79, 0xECECEC)
      $1stcoords = PixelSearch(930, 621, 1066, 649, 0x8A211E)
      $point = MouseGetPos()
      $posx = Random(930, 1066)
      $posy = Random(621, 649)
      $clicklogx = Random(1076, 1093)
      $clicklogy = Random(38, 54)
      If IsArray($Coords) Then ;check to see if the first color is there
         If IsArray($1stcoords) Then ;if it is check for the second color and if that one is there:
         MouseClick( "left", $point[0], $point[1], 1)
         If IsArray(<>$1stcoords) Then ;if the second color is not there:
         MouseClick("left", $clicklogx, $clicklogy, 1, Random(1000, 2500))
         Sleep(3000)
         MouseClick( "left" , $posx, $posy, 1, Random ( 1000 , 2500))
      EndIf
      EndIf
      EndIf
      Sleep(2000)
   WEnd
EndFunc

While 1
   Sleep(250)
WEnd

 

Edited by Warriorfoe

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Welcome to AutoIt and the forum!

Pixelsearch and Mouseclick are not very reliable as they depend on window position and screen size etc.
Could you please tell us which program you try to automate? Most of the time there are more reliable ways to do what you want to do.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2016-07-20 - Version 1.2.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Ya I'm trying to automate logging out on RuneScape. Like I'm not trying to bot or anything I just want to see if this script works in the game. I'm doing this on a throwaway account but I doubt the owners will care if I'm just logging out. Basically I'm trying to have it search for a white dot on a certain area of the minimap and if it finds that color it will check to see if the logout button is there. If it finds it it will just click on it and if it doesn't it will bring it up on the menu and then click on it. Idk I figured I'd try one of my first scripts there cause I play a lot and I just wanted to see if it would work.

Share this post


Link to post
Share on other sites

@Warriorfoe unfortunately this still falls afoul of the forum rules.

Quote
  • Launching, automation or script interaction with games or game servers, regardless of the game.

 


When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

  • Similar Content

    • Masum
      If conditions not working
      By Masum
      Hi all,
      I'm going crazy while I try and work out why a fairly simply if condition isn't working. I will try and explain it clearly, in the hope someone can find out the cause. The portion of the script for these if conditions is copied in below. The first PixelGetColor func is denoted in Screenshot 1, the RED dot signifies where the color is extracted from. The second PixelGetColor func is denoted in Screenshot 2, the YELLOW dot signifies where the color is extracted from. The script is tested for 3 scenarios, where 1. no resource is found (Screenshot 1), 2. multiple resources are found (Screenshot 2), and 3. only 1 resource is found (Screenshot 3). This application is being run via RDP hence I can't access the controls, and therefore relying on the pixel colours. The issue is, for all three scenarios, only the first If condition's first result is shown, even though the actual program shows the 3 screenshots for each of the three scenarios. Any ideas where I'm going wrong?
      If PixelGetColor(697, 446, 0xF0F0F0) Then ;If resource is not found, cancel out
              Sleep(200)
              MsgBox(64, 'Error', 'Resource is not found, therefore this pool will not be saved and will cancel out. Click OK to continue.')
              _Excel_RangeWrite($oWorkbook, 'CHFT Pools & RTE Rules', 'Fail', 'I' & $ColumnIRow)
              _Excel_RangeWrite($oWorkbook, 'CHFT Pools & RTE Rules', 'Resource not found. ' & $Notes, 'J' & $ColumnIRow)
              Sleep(500)
              WinActivate('Scheduling Help')
              Sleep(500)
              Send('{ENTER}') ;Click OK
              Sleep(500)
              Send('{SHIFTDOWN}{TAB}{SHIFTUP}{ENTER}') ;Click Cancel
              Sleep(500)
              Send('{SHIFTDOWN}{TAB}{TAB}{TAB}{TAB}{SHIFTUP}{ENTER}') ;Click Close
              Sleep(500)
              WinActivate('Scheduling: DB Flex Rule Tool - Inbox Pool Routing')
              Sleep(500)
              Send('{TAB}{ENTER}') ;Click Yes
              Sleep(500)
              WinActivate('Rules for Pool')
              Sleep(500)
              Send('{TAB}{TAB}{TAB}{ENTER}') ;Click Cancel
              Sleep(500)
              MouseClick('Primary', 1259, 653, 1) ;Click Cancel
          Else
              Send('{TAB}{TAB}{DOWN}') ;Find resource
              If PixelGetColor(725, 383, 0x3399FF) Then ;If there are multiple resources, cancel out
                  Sleep(200)
                  MsgBox(64, 'Error', 'There are multiple resources, therefore this pool will not be saved and will cancel out. Click OK to continue.')
                  _Excel_RangeWrite($oWorkbook, 'CHFT Pools & RTE Rules', 'Redo', 'I' & $ColumnIRow)
                  _Excel_RangeWrite($oWorkbook, 'CHFT Pools & RTE Rules', 'Multiple resources. ' & $Notes, 'J' & $ColumnIRow)
                  Sleep(500)
                  WinActivate('Scheduling Help')
                  Sleep(500)
                  Send('{TAB}{TAB}{ENTER}') ;Click Cancel
                  Sleep(500)
                  Send('{SHIFTDOWN}{TAB}{TAB}{TAB}{TAB}{SHIFTUP}{ENTER}') ;Click Close
                  Sleep(500)
                  WinActivate('Scheduling: DB Flex Rule Tool - Inbox Pool Routing')
                  Sleep(500)
                  Send('{TAB}{ENTER}') ;Click Yes
                  Sleep(500)
                  WinActivate('Rules for Pool')
                  Sleep(500)
                  Send('{TAB}{TAB}{TAB}{ENTER}') ;Click Cancel
                  Sleep(500)
                  MouseClick('Primary', 1259, 653, 1) ;Click Cancel
              Else ;Select the resource
                  Send('{ENTER}') ;Select Order Physician
                  MsgBox(0, '', 'save button clicks now')
                  _Excel_RangeWrite($oWorkbook, 'CHFT Pools & RTE Rules', 'Complete', 'I' & $ColumnIRow)
                  _Excel_RangeWrite($oWorkbook, 'CHFT Pools & RTE Rules', 'Success. ' & $Notes, 'J' & $ColumnIRow)
                  ;Send('{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{ENTER}') ;Click Save
              EndIf
          EndIf

    • SaeidN
      Select or Switch or If ?
      By SaeidN
      Hi,
      I want to tell pixelsearch to search for red color shades in for example 5 different x,y,h,w of the screen. If color red was not found in these 5 area, then do something.
      I wrote this, but it's working only if the first case is not found. Is select a good choice? or it's better to use switch or if or something else?
      ٍEdit: all "do something"s are same function. (search for red color untill in these 5 areas, it couldnot find red color, then if it couldn't find red color, perform that 1 function)
      Thanks
      Select Case 1 $color1 = PixelSearch(67, 614, 77, 617, 0xE62121, 10) If @error Then do something... EndIf Case 2 $color2 = PixelSearch(165, 614, 175, 617, 0xE62121, 10) If @error Then do something... EndIf Case 3 $color3 = PixelSearch(265, 614, 275, 617, 0xE62121, 10) If @error Then do something... EndIf Case 4 $color4 = PixelSearch(365, 614, 375, 617, 0xE62121, 10) If @error Then do something... EndIf Case 5 $color5 = PixelSearch(465, 614, 475, 617, 0xE62121, 10) If @error Then do something... EndIf EndSelect  
    • ZeroByDevide
      while loop
      By ZeroByDevide
      so right now i have a small project and i wanted to print this text out every second.
      i have made a random number for the sleep function. but when i want to print out with the while loop it just doesn't work.
      Run("notepad.exe") Sleep(1000) Local $rndSleep = Int (Random(180000,240000,1000)) While $rndSleep <> 0 $rndSleep - 1 If Mod ( $rndSleep, 1000 ) == 0 Then Send("This note will show the sleeptime before closing the tabs, you got " & $rndSleep & " seconds left.") EndIf WEnd plis halp me 
    • JJ1122
      I'm stuck with while/if loop... please help!
      By JJ1122
      #include <Misc.au3>
      While 1
         If _IsPressed(59) Then
            Send("{B}")
            MouseDown("left")
         Else
            Send("{B}")
            MouseUp("left")
         EndIf
      WEnd
       
      I want the script to do this:
      - if I press "Y", send "B" once and hold left click down until i release "Y".
      - if I take my hands off of "Y" key, then send "B" once again and release left click.
       
      but the script I made has problems.
      when I run the script, it starts sending "B" repeatedly, and my left click won't work.
       
      I'm not smart enough to figure out what the problem is... please help me!
      sorry for bad English.
       
    • TheFixer
      if not wintitle = "x" then
      By TheFixer
      Basically i am trying to make a script that detects if the currently active window is 1920 x 1080 or bigger. If it detects a window that is active, that is indeed that size. It will do some stuff. 
      The problem i am having is that it is detecting my desktop whenever i click on my desktop, so it's doing stuff when i don't want it to.

      So all i need to know, is how can i do a simple check to see if a window = a title.

      Here is what i have so far
      $wintitledesktop = WinGetTitle("[ACTIVE]") If not $wintitledesktop = "Program Manager" Then ;does stuff endif Program Manager is what my desktop is called btw. 

      The problem with that code is that the script is still detecting the desktop and doing the code.
       
      In case you need the whole section of the code, here it is.

       
      $winsizecheck1 = WinGetClientSize("[ACTIVE]") $wintitledesktop = WinGetTitle("[ACTIVE]") If WinActive("[ACTIVE]") Then sleep(100) If $winsizecheck1[0] >= 1920 Then If $winsizecheck1[1] >= 1080 Then If not $wintitledesktop = "Program Manager" Then $gamesfolderstate = WinGetState($gamesfolder) If WinExists($gamesfolder) Then If Not BitAND($gamesfolderstate, 16) Then WinSetState($gamesfolder,"",@SW_MINIMIZE) EndIf EndIf EndIf EndIf EndIf EndIf