|
You last visited: Today at 04:05
Advertisement
Too many if statements?
Discussion on Too many if statements? within the AutoIt forum part of the Coders Den category.
06/08/2016, 01:38
|
#1
|
elite*gold: 10
Join Date: Oct 2011
Posts: 71
Received Thanks: 9
|
Too many if statements?
Hi there!
I'm working on a bot, suddenly my If code doesn't work. Is there a limit for if links?
I'm 100% sure the Pixelcolor fits since I checked with ControlViewer.
I was just adding more and more "or if and if" statements. I even tried to create a new if loop. What is the mistake?
Edit: Also I'm getting this in console:
>"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "@ScriptFullPath"
What does /ErrorStdOut mean?
On the bottom
Code:
Code:
#include <GUIConstantsEx.au3>
Global $status="lade..."
;GUI
Global $StatusAnzeige
GUICreate("My GUI")
$statusanzeige = GuiCtrlCreateLabel($status,5,5)
Local $debugresetstatus = GUICtrlCreateButton("reset", 120, 170, 85, 25)
GUISetState(@SW_SHOW)
Opt("GUIOnEventMode", 1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Close")
GUICtrlSetOnEvent($debugresetstatus, "_reset")
Func _reset ()
$status="reset"
EndFunc
;ControlPixel
AutoItSetOption ("pixelcoordmode", 2)
;X heißt close
Func _Close()
GUIDelete()
Exit
EndFunc
;Getwndow get PID
;2. get window every xy by pid
Func _GetHwndFromPID($PID)
$hWnd = 0
$stPID = DllStructCreate("int")
Do
$winlist2 = WinList()
For $i = 1 To $winlist2[0][0]
If $winlist2[$i][0] <> "" Then
DllCall("user32.dll", "int", "GetWindowThreadProcessId", "hwnd", $winlist2[$i][1], "ptr", DllStructGetPtr($stPID))
If DllStructGetData($stPID, 1) = $PID Then
$hWnd = $winlist2[$i][1]
ExitLoop
EndIf
EndIf
Next
Sleep(100)
Until $hWnd <> 0
Return $hWnd
EndFunc ;==>_GetHwndFromPID
AdlibRegister("status",1000)
Func status ()
GuiCtrlSetData($StatusAnzeige,$status)
EndFunc
While 1
;Handle nachtragen
if PixelGetColor(933,177)=0xAB3051 And PixelGetColor(1017,167)=0xFE4D59 or PixelGetColor(933,177)=0x181810 And PixelGetColor(1150,35)=0xBD4563 Or PixelGetColor(1132,333)=0x453333 And PixelGetColor(378,105)=0xF4D491 Or PixelGetColor(914,193)=0xB23557 And PixelGetColor(998,176)=0xF3434C Or PixelGetColor(707,204)=0x473434 And PixelGetColor(1630,866)=0x9C3CAD Or PixelGetColor(889,180)=0x9E2644 And PixelGetColor(973,157)=0xEF464D Or PixelGetColor(775,428)=0x4B3632 And PixelGetColor(1259,77)=0xB13D5E Or PixelGetColor(934,173)=0xB53157 And PixelGetColor(1005,146)=0xF2545A Or PixelGetColor(891,171)=0xB12E54 And PixelGetColor(969,156)=0xFC5159 Or PixelGetColor(938,173)=0xB03B5C And PixelGetColor(1012,159)=0xF64C57 Or PixelGetColor(956,168)=0xB6395B And PixelGetColor(1031,149)=0xF1434D Or PixelGetColor(872,186)=0xBD4163 And PixelGetColor(946,167)=0xE1494C Or PixelGetColor(919,163)=0xB13958 And PixelGetColor(986,157)=0xEC4A52 Or PixelGetColor(964,132)=0xA22D4F And PixelGetColor(1028,140)=0xFB4951 Or PixelGetColor(413,172)=0xA22D4F And PixelGetColor(472,174)=0xF16767 Or PixelGetColor(948,105)=0x862644 And PixelGetColor(1006,123)=0xEC4A52 Then
$status="karte1"
EndIf
If PixelGetColor(1208,96)=0xAD3851 And PixelGetColor(1280,67)=0xF94D54 or PixelGetColor(1214,83)=0xA22D48 And PixelGetColor(1279,67)=0xF45C5E or PixelGetColor(990,132)=0x822040 And PixelGetColor(1035,133)=0xF84C55 Then
$status="karte1"
EndIf
; Sleep(1000)
; $status="Status1"
; Sleep(1000)
; $status="Status2"
WEnd
|
|
|
06/08/2016, 06:05
|
#2
|
elite*gold: 60
Join Date: Aug 2009
Posts: 2,256
Received Thanks: 815
|
There is no specific amount of allowed if-statements within an AutoIt3 script so you can make how much you want.
As far as my PC is concerned your script seems to run just fine and the syntax check doesn't spit out something suspicious.
Why don't you go ahead and post the error you get?
/ErrStdOut just means to reflow the error output of the console to the normal output.
This is an option because the console usually has two outputs, normal and error and since some programs are reading only the normal console instead of the error one too /ErrStdOut redirects it so it gets displayed within the SciTE Console Monitor.
By the way, I'd heavily recommend you to rework your code especially the PixelGetColor lines because that is an inefficient way of programming. Why don't you make an array containing the coordinates and colors and iterating through it while checking every index to see if all the color matches? If one fails you can immediately break then.
|
|
|
06/08/2016, 16:51
|
#3
|
elite*gold: 10
Join Date: Oct 2011
Posts: 71
Received Thanks: 9
|
Quote:
As far as my PC is concerned your script seems to run just fine and the syntax check doesn't spit out something suspicious.
Why don't you go ahead and post the error you get?
|
Thats my Problem. I don't get any errors. The PixelGetColor lines suddenly stopped working as I was adding more. $status doesn't change to "karte1" but it should. The Coordinates fit and the color fits too.
Quote:
Thank you for your explanation.
Quote:
|
By the way, I'd heavily recommend you to rework your code especially the PixelGetColor lines because that is an inefficient way of programming. Why don't you make an array containing the coordinates and colors and iterating through it while checking every index to see if all the color matches? If one fails you can immediately break then.
|
I Struggle understanding what you mean. I'm not very good in autoit I can't properly code what I think you mean. I needed Hours to make my Code from above. Something Like this?:
Code:
Global $checkthis[3]
While 1
if PixelGetColor ($checkthis[1],$checkthis[2]= $checkthis[3] Then
$status="karte1"
EndIf
$checkthis[1]=
$checkthis[2]=
$checkthis[3]=
;Do a loop to change. How?
WEnd
EDIT: Or more like this?
Code:
Global $i=3
Global $xpixel[$i] = ["pixel1","pixel2","pixel3"]
Global $ypixel[$i] =["pixel1","pixel2","pixel3"]
Global $color[$i] =["color1","color2","color3"]
While 1
For $i =1 To 3
if PixelGetColor ($xpixel[$i],$ypixel[$i]= $color[$i] Then
$status="karte1"
EndIf
Next
WEnd
What lines beside the PixelGetColor ones are inefficient?
|
|
|
06/08/2016, 19:58
|
#4
|
elite*gold: 60
Join Date: Aug 2009
Posts: 2,256
Received Thanks: 815
|
The performance of your script won't vary much by stuffing the pixel information into arrays but it will make it a LOT easier and better to read. I'd suggest you to do something like this
Code:
Global $aPixel[2][3] = [[900, 800, 0xABABAB], [800, 700, 0xABACAD]]
;and then iterating through the array with this logic
For $i = 0 To UBound($aPixel) - 1
;This may not serve your purpose since you're linking And and Ors in the long if-statement
;so adjust this for your needs.
If Not PixelGetColor($aPixel[$i][0], $aPixel[$i][1]) = $aPixel[$i][2] Then
$status = ""
Else
$status = "karte1"
EndIf
Next
Since you're saying that it suddenly stopped working I'd like to know what happened when it stopped working. If it's not spitting out any errors then the program must exit itself somehow.
|
|
|
06/08/2016, 22:26
|
#5
|
elite*gold: 10
Join Date: Oct 2011
Posts: 71
Received Thanks: 9
|
Thank you for that eye openener! For now I leave the code because I need to know which pixel fit for debugging. But I keep that in mind!
I work like this
I play the game
start the map
see if status changes - if repeat.
If not add 2 Pixelgetcolor to the code
Compile it and run it again without moving ingame.
Status changes now. - Repeat.
I'm not 100% sure but very sure I didn't change the code in another place than in the Pixelgetcolor if's. But the status doesn't change anymore. Even if I add new coordinates without moving.
I get no error but Pixelgetcolor doesn't work/ there seem to be an error. The script is running, I can reset $status through the GUIbutton and the tray icon exists.
It stoped working within one save. I think I just added 2 Pixelgetcolor. I could find any mistake, but tbh I might not see everything.
Is there any way to debug line by line?
|
|
|
06/08/2016, 23:48
|
#6
|
elite*gold: 60
Join Date: Aug 2009
Posts: 2,256
Received Thanks: 815
|
Quote:
Originally Posted by O-Drop
Thank you for that eye openener! For now I leave the code because I need to know which pixel fit for debugging. But I keep that in mind!
I work like this
I play the game
start the map
see if status changes - if repeat.
If not add 2 Pixelgetcolor to the code
Compile it and run it again without moving ingame.
Status changes now. - Repeat.
I'm not 100% sure but very sure I didn't change the code in another place than in the Pixelgetcolor if's. But the status doesn't change anymore. Even if I add new coordinates without moving.
I get no error but Pixelgetcolor doesn't work/ there seem to be an error. The script is running, I can reset $status through the GUIbutton and the tray icon exists.
It stoped working within one save. I think I just added 2 Pixelgetcolor. I could find any mistake, but tbh I might not see everything.
Is there any way to debug line by line?
|
Natively in SciTE Code Walkthrough is not supported, you have to use an AutoIt3 IDE for that (there is one but it's kinda outdated).
I'd recommend you to put the colors in the array and then simply check if one color doesnt match, then you can easily tell at which index you are in the array and that maybe holds the wrong colorcode?
|
|
|
06/09/2016, 00:41
|
#7
|
elite*gold: 10
Join Date: Oct 2011
Posts: 71
Received Thanks: 9
|
I just deleted the whole Pixelgetcolor stuff and started over with 2 new coordinates. It worked! Even in my old script. I don't know why. Nvm I will rework this.
Ist there a better way than switch to prevent $i from getting beyond 0? I'm getting a badly formated code error then. Since I always want to check 2 Pixel I need to work with +/-1. But going unbound+1 doesn't work too.
My code so far:
Code:
Global $aPixel[2][3] = [[915, 160, 0xCA3E61], [983, 139, 0xFF595A]]
While 1
For $i = 0 To UBound($aPixel) - 1
Switch $i
case 1 To 1000
If PixelGetColor($aPixel[$i][0], $aPixel[$i][1]) = $aPixel[$i][2] And PixelGetColor ($aPixel[$i-1][0], $aPixel[$i-1][1]) = $aPixel[$i-1][2] Then
$status = "Karte1"
Else
$status = ""
EndIf
EndSwitch
Sleep (500)
Next
WEnd
|
|
|
06/09/2016, 01:15
|
#8
|
elite*gold: 60
Join Date: Aug 2009
Posts: 2,256
Received Thanks: 815
|
Why are you switching the $i, what are you trying to achieve with that?
The For-Loop is adjusted to iterate through every single element of the $aPixel array so you only have to do your check.
If $aPixel's dimension is [2][3] the For-Loop will go: 0, 1, stop.
Oh, you're trying to compare two pixels at once. Well you have many ways to choose from.
Either you simply change the [2][3] to [2][6] and put the other pixel data in the same index just behind the old one....
Or you adjust the For-Loop to something like this
Code:
Global $aPixel[2][3] = [[915, 160, 0xCA3E61], [983, 139, 0xFF595A]]
While 1
For $i = 1 To UBound($aPixel) - 1 Step 2
If PixelGetColor($aPixel[$i][0], $aPixel[$i][1]) = $aPixel[$i][2] And PixelGetColor ($aPixel[$i-1][0], $aPixel[$i-1][1]) = $aPixel[$i-1][2] Then
$status = "Karte1"
Else
$status = ""
EndIf
Sleep (500)
Next
WEnd
This will make it go in two steps for each incrementation instead of 1 and will end on the last index by starting at the second. So it will go like this: $aPixel dimension: [10][3] - 1, 3, 5, 7, 9, stop.
|
|
|
 |
Similar Threads
|
Learn SQL statements...where?
08/14/2014 - General Coding - 9 Replies
Hello,
i had some basic SQL this year at school, but i feel like i didnt really learn that much, just basic stuff... like SELECT, UPDATE, DELETE, etc..
Does anyone know a site or something where i could learn to use more advanced SQL senteces?
|
[RELEASE] Usefull SQL statements - for GM's
02/07/2011 - Shaiya PServer Development - 16 Replies
This one lists all items that can drop from any particular monster. The one I post here will return MobName, ItemName, Grade, DropChance. You can add more if you want to.
To make it work type the monster name between the percent signs (red colour). It doesn't have to be the full name. Partial names will work too, i.e. '%Ruined Wolf%', '%Cryptic%':
DECLARE @MobName varchar(60);
SET @MobName = '%%';
SELECT M.MobName, I.ItemName, MI.Grade, MI.DropRate
|
hackers out there! u can post ur statements here ^^
05/13/2009 - Grand Chase - 32 Replies
juz read the rules over and over again (5x actually) im hopin that this thread will somehow enlightened those MISUSERS on how to use their hacks or someone else's properly. and i guess that this post will not break any of this forum's rules so.. here we go!
Why or what is/are the reason/s why you are using hacks in the game? ;)
ME= use this hacks coz i want to catch up to my friends playin for a whole weekend w/c are lvl 50+. ( i do have a job ) i guess this hacks really makes me...
|
All times are GMT +1. The time now is 04:07.
|
|