Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > AutoIt
You last visited: Today at 21:07

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



AutoIt Question about If Statement ;)

Discussion on AutoIt Question about If Statement ;) within the AutoIt forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Jul 2007
Posts: 219
Received Thanks: 43
AutoIt Question about If Statement ;)

Just want to ask if this example could work

if not, then tell me how to make it correct way

(Can anyone tell me why code i writed dont work, Tried to do it in many ways but i cant figure out how to fix it and make it works...)


Cause i tried many times to make it Heal and if dont need to use heal then start next function way, but i cant figure out how to make it correctly, And when i use simple
if not(@error) then
else
if @error then
it skip sometimes alot of code lines
Example i tried to make Go from path 1 to path 2
and it were going only to path one even if i added to script check if at path 1 point then go to path point 2 but it was clicking only on path 1 point -,-

This time im going to make it this way ==> If ($first And $second and $third) = False Then
StartFunction()

But b4 ill start it i need to know if script i post above work correctly
owadziak is offline  
Old 07/25/2017, 18:09   #2
 
mlukac89's Avatar
 
elite*gold: 0
Join Date: Sep 2010
Posts: 473
Received Thanks: 104
Try this way, you have many extra code that you don't need.

Just check for error, if no error do something else, but first you need to make a skeleton with comments what you want to do and in what part.

There you go test this script if works, if not put comments in where you want what and edit post.

Code:
Func _Heal() ;; Gotowe
	
	$GetHP = PixelSearch(276,79,292,80,0x202020,1)
	If @Error Then
		Send("{0}")
		Sleep(100)
	Else
		_OpenChest() ; if not healing then search for Chest button
	EndIf

EndFunc
;=============
Func _OpenChest() ;; Gotowe
	
	$ChestAppear = PixelSearch(1023,629,1038,634,0x264007,1)
	
	If @error Then
		Global $ChestButtonToClick = 1
	Else
		Global $ChestButtonToClick = 0 ; delete if you dont use
		
		$Chest = PixelSearch(1023,629,1038,634,0x264007,1)
        If @error Then
			_PickDrop() ; if false then start picking function
        Else
			MouseClick("Left",$Chest[0],$Chest[1],1,1)
            Sleep(50)
        EndIf
	EndIf

EndFunc
;==================
Func _PickDrop() ;; Gotowe

    $DropAppear = PixelSearch(39,178,1305,541,0xFDFDFD,1)

	If @error Then
        Global $SomethingToLoot = 0
		$Drop = PixelSearch(39,178,1305,541,0xFDFDFD,1)
        If @error Then
			_LetsFight() ; If false then start fighting
        Else
			MouseClick("Left",$Drop[0],$Drop[1],1,1)
            Sleep(50)
		EndIf
	Else
        Global $SomethingToLoot = 1
	EndIf
	
EndFunc
mlukac89 is offline  
Old 07/26/2017, 08:30   #3
 
mhaendler's Avatar
 
elite*gold: 0
Join Date: Jul 2008
Posts: 1,826
Received Thanks: 226
Code:
Func _PickDrop() ;; Gotowe
    $DropAppear = PixelSearch(39,178,1305,541,0xFDFDFD,1)

    If @error Then
        Global $SomethingToLoot = 0
        $Drop = PixelSearch(39,178,1305,541,0xFDFDFD,1)
        If @error Then
            _LetsFight() ; If false then start fighting
        Else
            MouseClick("Left",$Drop[0],$Drop[1],1,1)
            Sleep(50)
	EndIf
    Else
        Global $SomethingToLoot = 1
    EndIf
EndFunc
You shouldn't declare Global Variables in a Function, that way its to easy to get confused by which scope the variable is declared. Which leads to errors later on

Inside Function use: Local $SomethingToLoot if the useage of the variable is only in the context of the function. If you need this variable in multiple functions, declare the variable at the head of your script with global and then simply use it through the different function (some might say this is dirty, but its a better way then the current way).

I dont say this is the best way to code!

Also work on your Intends, they are pretty slope and you may get lost in your code!

BTW. What is your script supposed to do / what doesn't work

_mhaendler
mhaendler is offline  
Old 07/26/2017, 17:15   #4
 
elite*gold: 0
Join Date: Jul 2007
Posts: 219
Received Thanks: 43
I figured how to fix it my self
Rewrited whole script and changed it to this

and now it all works correctly (even that double pixelsearch for item pixel)
just now i need to add hunting to it and Path finding

Btw. I added a double mouse left click cause if u want to loot a drop u need to click on it twice in game
owadziak is offline  
Old 07/27/2017, 10:52   #5
 
mhaendler's Avatar
 
elite*gold: 0
Join Date: Jul 2008
Posts: 1,826
Received Thanks: 226
Quote:
Originally Posted by owadziak View Post
I figured how to fix it my self
Rewrited whole script and changed it to this

and now it all works correctly (even that double pixelsearch for item pixel)
just now i need to add hunting to it and Path finding

Btw. I added a double mouse left click cause if u want to loot a drop u need to click on it twice in game
MouseClick does provide double click just change:

You should add this file:

Code:
#include <AutoItConstants.au3>
Code:
MouseClick("Left", $Loot2[0], $Loot2[1], 1, 1)
to
Code:
;$MOUSE_CLICK_PRIMARY Clicks the primary mouse, in case a use has a left handed mouse
MouseClick($MOUSE_CLICK_PRIMARY, $Loot2[0], $Loot2[1], 2) ; the last parameter "2" does a double click so you dont need to call the function twice ;)
_mhaendler
mhaendler is offline  
Old 07/27/2017, 12:49   #6
 
elite*gold: 0
Join Date: Jul 2007
Posts: 219
Received Thanks: 43
Quote:
Originally Posted by mhaendler View Post
MouseClick does provide double click just change:

You should add this file:

Code:
#include <AutoItConstants.au3>
Code:
MouseClick("Left", $Loot2[0], $Loot2[1], 1, 1)
to
Code:
;$MOUSE_CLICK_PRIMARY Clicks the primary mouse, in case a use has a left handed mouse
MouseClick($MOUSE_CLICK_PRIMARY, $Loot2[0], $Loot2[1], 2) ; the last parameter "2" does a double click so you dont need to call the function twice ;)
_mhaendler
Ty mate
Btw do u have skype or something else that we can use to talk a bit ?
I got few more questions
owadziak is offline  
Reply




All times are GMT +1. The time now is 21:08.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.