Sign in to follow this  
Followers 0
Lazzo

If sentence

7 posts in this topic

okay so as you can imagine I'm a total noob here, just started learning, so for my first project I tried to make a simple mouse clicker but it doesnt seem to work =/

Func BotStart()
   $pt = PixelSearch (625, 405, 1284, 942, 0xD2D2D2)
   sleep(500)
   if Not @error Then
        mouseclick( "left", $pt[0], $pt[1], 1, 0)
        Sleep (500)
        $coord1 = PixelSearch (638, 349, 1299, 790, 0xFF0000)
        Sleep (1000)
        MouseClick ( "left", $coord1[0], $coord1[1], 1, 0)
        Sleep (650000)
        MouseClick ( "left", 485, 132, 1, 0)
        Sleep (1000)
      
  Else
      Sleep(55000)
      Return
EndIf
EndFunc

While 1

MouseClick ( "left", 853, 230, 1, 0)
Sleep (3000)    
Call("BotStart")
Wend

so, it clicks on 853,230 and start the botstart function where it searches for a color in the box and if it finds the color it does aditional clicks, if it does not find the color it sleeps then starts again

but my problem is that if it does not find the color it does not sleep but gives me an error at mouseclick( "left", $pt[0], $pt[1], 1, 0) saying subscript used with non-Array variable

I understand its because the pixelsearch did not return any coordinates but why did it not jump to the else statement? :S

I even tried with if IsArray($pt) then.... else... but I get the same error lol

I'm really stuck atm :S

Share this post


Link to post
Share on other sites



Two things to consider:

it does not sleep

Sleep(500) only sleeps half a second. So you won't notice the delay.

if it does not find the color

In your code you check @error after the Sleep command - so you check the @error code of Sleep. Move the Sleep after the error checking.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Two things to consider:

Sleep(500) only sleeps half a second. So you won't notice the delay.

In your code you check @error after the Sleep command - so you check the @error code of Sleep. Move the Sleep after the error checking.

oh damn, didnt realize it checks @error for sleep then, how silly am I ;)

Thanks a lot!

Edited by Lazzo

Share this post


Link to post
Share on other sites

It works fine for me. I get "Not found" written to the SciTE console.

Botstart()
Func BotStart()
    $pt = PixelSearch(625, 405, 1284, 942, 0xD2D2D2)
    If Not @error Then
        ConsoleWrite("Found" & @CRLF)
        Sleep(500)
        MouseClick("left", $pt[0], $pt[1], 1, 0)
        Sleep(1000)
        $coord1 = PixelSearch(638, 349, 1299, 790, 0xFF0000)
        Sleep(1000)
        MouseClick("left", $coord1[0], $coord1[1], 1, 0)
        Sleep(650000)
        MouseClick("left", 485, 132, 1, 0)
        Sleep(1000)

    Else
        ConsoleWrite("Not found" & @CRLF)
        Sleep(55000)
        Return
    EndIf
EndFunc ;==>BotStart

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

What are you trying to achieve with your script? The function name sounds a bit suspicious.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

yeah it works, I started the wrong script earlyer lol

this one just clicks links

gona try some window popups next ;)

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