|
You last visited: Today at 21:07
Advertisement
AutoIt Question about If Statement ;)
Discussion on AutoIt Question about If Statement ;) within the AutoIt forum part of the Coders Den category.
07/25/2017, 14:45
|
#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
PHP Code:
Func _Heal() ;; Gotowe $GetHP = PixelSearch(276,79,292,80,0x202020,1) If not(@Error) Then _OpenChest() ; if not healing then search for Chest button Else If @Error Then Send("{0}") Sleep(100) EndIf EndIf EndFunc ;============= Func _OpenChest() ;; Gotowe $ChestAppear = PixelSearch(1023,629,1038,634,0x264007,1) If Not(@error) Then Global $ChestButtonToClick = 0 Else If @Error Then Global $ChestButtonToClick = 1 EndIf EndIf
If $ChestButtonToClick = 0 Then $Chest = PixelSearch(1023,629,1038,634,0x264007,1) If Not(@Error) Then MouseClick("Left",$Chest[0],$Chest[1],1,1) Sleep(50) Else If @Error Then _PickDrop() ; if false then start picking function EndIf EndIf EndIf
EndFunc ;================== Func _PickDrop() ;; Gotowe $DropAppear = PixelSearch(39,178,1305,541,0xFDFDFD,1) If Not(@Error) Then Global $SomethingToLoot = 0 Else If @Error Then Global $SomethingToLoot = 1 EndIf EndIf
If $SomethingToLoot = 0 Then $Drop = PixelSearch(39,178,1305,541,0xFDFDFD,1) If not(@Error) Then MouseClick("Left",$Drop[0],$Drop[1],1,1) Sleep(50) Else If @Error Then _LetsFight() ; If false then start fighting EndIf EndIf EndIf EndFunc
(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
|
|
|
07/25/2017, 18:09
|
#2
|
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
|
|
|
07/26/2017, 08:30
|
#3
|
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
|
|
|
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
PHP Code:
Func _StartBotting() While (1) HotKeySet("{F1}", _Exit) WinActivate("Example Game")
$Leczenie = PixelSearch(250, 80, 261, 81, 0x1D1D1D, 1, 1) If Not (@error) Then Send("{0}") Sleep(100) ElseIf @error Then $Chest = PixelSearch(1026, 628, 1032, 663, 0x264007, 1, 1) If Not (@error) Then MouseClick("Left", $Chest[0], $Chest[1], 1, 1) ElseIf @error Then $Loot = PixelSearch(1288, 533, 56, 172, 0xF6F6F6, 1, 1) If Not (@error) Then $Loot1 = PixelSearch($Loot[0] - 10, $Loot[1] - 10, $Loot[0] + 10, $Loot[1] + 10, 0x858685, 10, 1) If Not (@error) Then MouseClick("Left", $Loot[0], $Loot[1], 1, 1) sleep(1) MouseClick("Left", $Loot[0], $Loot[1], 1, 1) ElseIf @error Then $Loot2 = PixelSearch(1080, 599, 322, 99, 0xF6F6F6, 1, 1) If Not (@error) Then $Loot3 = PixelSearch($Loot2[0] - 10, $Loot2[1] - 10, $Loot2[0] + 10, $Loot2[1] + 10, 0x858685, 10, 1) If Not (@error) Then MouseClick("Left", $Loot2[0], $Loot2[1], 1, 1) sleep(1) MouseClick("Left", $Loot2[0], $Loot2[1], 1, 1) ElseIf (@error) Then $Mob1 = PixelSearch(41,135,1292,534,$ EndIf EndIf EndIf EndIf EndIf EndIf
WEnd EndFunc ;==>_StartBotting
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
|
|
|
07/27/2017, 10:52
|
#5
|
elite*gold: 0
Join Date: Jul 2008
Posts: 1,826
Received Thanks: 226
|
Quote:
Originally Posted by owadziak
I figured how to fix it my self
Rewrited whole script and changed it to this
PHP Code:
Func _StartBotting() While (1) HotKeySet("{F1}", _Exit) WinActivate("Example Game")
$Leczenie = PixelSearch(250, 80, 261, 81, 0x1D1D1D, 1, 1) If Not (@error) Then Send("{0}") Sleep(100) ElseIf @error Then $Chest = PixelSearch(1026, 628, 1032, 663, 0x264007, 1, 1) If Not (@error) Then MouseClick("Left", $Chest[0], $Chest[1], 1, 1) ElseIf @error Then $Loot = PixelSearch(1288, 533, 56, 172, 0xF6F6F6, 1, 1) If Not (@error) Then $Loot1 = PixelSearch($Loot[0] - 10, $Loot[1] - 10, $Loot[0] + 10, $Loot[1] + 10, 0x858685, 10, 1) If Not (@error) Then MouseClick("Left", $Loot[0], $Loot[1], 1, 1) sleep(1) MouseClick("Left", $Loot[0], $Loot[1], 1, 1) ElseIf @error Then $Loot2 = PixelSearch(1080, 599, 322, 99, 0xF6F6F6, 1, 1) If Not (@error) Then $Loot3 = PixelSearch($Loot2[0] - 10, $Loot2[1] - 10, $Loot2[0] + 10, $Loot2[1] + 10, 0x858685, 10, 1) If Not (@error) Then MouseClick("Left", $Loot2[0], $Loot2[1], 1, 1) sleep(1) MouseClick("Left", $Loot2[0], $Loot2[1], 1, 1) ElseIf (@error) Then $Mob1 = PixelSearch(41,135,1292,534,$ EndIf EndIf EndIf EndIf EndIf EndIf
WEnd EndFunc ;==>_StartBotting
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 ;)
Code:
#include <AutoItConstants.au3>
HotKeySet("{F1}", _Exit) ; dont put this into the while, because you only need to bind it once
Func _StartBotting()
While (1)
WinActivate("Example Game")
$Leczenie = PixelSearch(250, 80, 261, 81, 0x1D1D1D, 1, 1)
If Not (@error) Then
Send("{0}")
Sleep(100)
ElseIf @error Then
$Chest = PixelSearch(1026, 628, 1032, 663, 0x264007, 1, 1)
If Not (@error) Then
MouseClick($MOUSE_CLICK_PRIMARY, $Chest[0], $Chest[1], 1, 1)
ElseIf @error Then
$Loot = PixelSearch(1288, 533, 56, 172, 0xF6F6F6, 1, 1)
If Not (@error) Then
$Loot1 = PixelSearch($Loot[0] - 10, $Loot[1] - 10, $Loot[0] + 10, $Loot[1] + 10, 0x858685, 10, 1)
If Not (@error) Then
MouseClick($MOUSE_CLICK_PRIMARY, $Loot[0], $Loot[1], 2, 10)
ElseIf @error Then
$Loot2 = PixelSearch(1080, 599, 322, 99, 0xF6F6F6, 1, 1)
If Not (@error) Then
$Loot3 = PixelSearch($Loot2[0] - 10, $Loot2[1] - 10, $Loot2[0] + 10, $Loot2[1] + 10, 0x858685, 10, 1)
If Not (@error) Then
MouseClick($MOUSE_CLICK_PRIMARY, $Loot2[0], $Loot2[1], 2, 10)
ElseIf (@error) Then
$Mob1 = PixelSearch(41,135,1292,534,$
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
WEnd
EndFunc ;==>_StartBotting
_mhaendler
|
|
|
07/27/2017, 12:49
|
#6
|
elite*gold: 0
Join Date: Jul 2007
Posts: 219
Received Thanks: 43
|
Quote:
Originally Posted by mhaendler
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 ;)
Code:
#include <AutoItConstants.au3>
HotKeySet("{F1}", _Exit) ; dont put this into the while, because you only need to bind it once
Func _StartBotting()
While (1)
WinActivate("Example Game")
$Leczenie = PixelSearch(250, 80, 261, 81, 0x1D1D1D, 1, 1)
If Not (@error) Then
Send("{0}")
Sleep(100)
ElseIf @error Then
$Chest = PixelSearch(1026, 628, 1032, 663, 0x264007, 1, 1)
If Not (@error) Then
MouseClick($MOUSE_CLICK_PRIMARY, $Chest[0], $Chest[1], 1, 1)
ElseIf @error Then
$Loot = PixelSearch(1288, 533, 56, 172, 0xF6F6F6, 1, 1)
If Not (@error) Then
$Loot1 = PixelSearch($Loot[0] - 10, $Loot[1] - 10, $Loot[0] + 10, $Loot[1] + 10, 0x858685, 10, 1)
If Not (@error) Then
MouseClick($MOUSE_CLICK_PRIMARY, $Loot[0], $Loot[1], 2, 10)
ElseIf @error Then
$Loot2 = PixelSearch(1080, 599, 322, 99, 0xF6F6F6, 1, 1)
If Not (@error) Then
$Loot3 = PixelSearch($Loot2[0] - 10, $Loot2[1] - 10, $Loot2[0] + 10, $Loot2[1] + 10, 0x858685, 10, 1)
If Not (@error) Then
MouseClick($MOUSE_CLICK_PRIMARY, $Loot2[0], $Loot2[1], 2, 10)
ElseIf (@error) Then
$Mob1 = PixelSearch(41,135,1292,534,$
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
WEnd
EndFunc ;==>_StartBotting
_mhaendler
|
Ty mate
Btw do u have skype or something else that we can use to talk a bit ?
I got few more questions
|
|
|
All times are GMT +1. The time now is 21:08.
|
|