Wallfire Posted March 2, 2004 Share Posted March 2, 2004 (edited) first off, thank you jon for this software!!! i was about to start takin night classes to learn C so that i can make the simple scripts that your autoit does. eventully when my code gets close enough to completion i will need to go back to C, but untill then your program gives me a easier way of writing scripts. thank you! anyways, heres my Q: im in a while loop and i want to hit the DOWN button once the first time through the loop, twice the second time, three times the thrid etc... here is what i got: While $i<$MAX Send("{DOWN $i}") $i=$i+1 WEnd in theory i should be increasing by one each interation and the amount of TABs should also increase. the way it runs now the code hits the DOWN key only once each time. perhaps my i is not increasing? that is the only thing i can think of, ill check that right now but i cant see what is wrong. let me know if anyone can help me out here: ICQ: 165801955 would my entire code also be helpful? Edited March 2, 2004 by Wallfire :cheer: awww...wheres the chick? Link to comment Share on other sites More sharing options...
Developers Jos Posted March 2, 2004 Developers Share Posted March 2, 2004 you have the variable in the literal... try it this way: While $i<$MAX $key = "{DOWN " & $i & "}" Send($key) $i=$i+1 WEnd SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Wallfire Posted March 2, 2004 Author Share Posted March 2, 2004 OK, thanks. ill try that. what you did kinda makes sense, you defined a ?varible? as the send DOWN command and added in the number of times to hit it with the & command. what i dont understand is why you used 2 &'s and why was double quotes around the "& $i &" needed? $key = "{DOWN " & $i (&) "}" i dont see why the & in () is needed, could you explain? what part of the help file would the '$key=' be under? :cheer: awww...wheres the chick? Link to comment Share on other sites More sharing options...
Developers Jos Posted March 2, 2004 Developers Share Posted March 2, 2004 (edited) Explanation of this statement:$key = "{DOWN " & $i & "}"- Anything between double quotes "" or single quotes '' is a literal (fixed string info).- The variable $key is formed by combining the following pieces of information :"{DOWN "$i"}"to combine Strings you use the &So if $i = 1 then"{DOWN " & 1 & "}" will be formed to "{DOWN 1}" Ok? Edited March 2, 2004 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Wallfire Posted March 2, 2004 Author Share Posted March 2, 2004 JdeB, Thanks for the explaination. i get it now. you just made a string that looked like {DOWN $i}. yay! im at work, but i cant wait to get home and try it out. larry, thanks also. am i allowed to do what you did without defining the $key as a string? ill try both ways, if your way works ill use it, less lines of code=good heres another problem i was having: with the same code, just in a differnet part. i used the autoscript writer at first just to give me a base to work off of [im very new to autoit and do not know the syntax]. when i clicked into a window it made WinWait stuff that made sure when the script was running in that window. when i wrote my code i just cut and pasted from what the autoscript writer made thinking that it should work, but when i run the script it would close the IE window i was working in and reboot/hybernate/shutdown my comp!! i thought this was very odd, and with enough troubleshooting i found that the lines of code that had to do with WinWait were causing the shutdowns. any idea why the script would shut down the computer? i can maybe understand shutting down the browser, but to send a kill comand to the OS seems kinda odd... :cheer: awww...wheres the chick? Link to comment Share on other sites More sharing options...
Developers Jos Posted March 2, 2004 Developers Share Posted March 2, 2004 Can you post the code portion that is causing your computer to shutdown? if its to big you can also PM or mail it and i would be happy to have a look at it. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Wallfire Posted March 2, 2004 Author Share Posted March 2, 2004 once i get home ill try and see if i have a older copy of the code. once i found out what lines were casuing the computer to shutdown i took them out. didnt bother to save 'em. :cheer: awww...wheres the chick? Link to comment Share on other sites More sharing options...
Wallfire Posted March 3, 2004 Author Share Posted March 3, 2004 hey, i had to dig through my trash but i found the lines of code that were messing it up: Opt("MouseCoordMode",0) WinWait("The Utopian Battlefields - Microsoft Internet Explorer provided by Comcast","") If Not WinActive("The Utopian Battlefields - Microsoft Internet Explorer provided by Comcast","") Then WinActivate("The Utopian Battlefields - Microsoft Internet Explorer provided by Comcast","") WinWaitActive("The Utopian Battlefields - Microsoft Internet Explorer provided by Comcast","") :cheer: awww...wheres the chick? Link to comment Share on other sites More sharing options...
Developers Jos Posted March 3, 2004 Developers Share Posted March 3, 2004 Don't think these line of code will make your pc reboot. What will happen is that when the Window with the title "The Utopian Battlefields - Microsoft Internet Explorer provided by Comcast" doesn't exists or doesn't have the focus, the script will be waiting forever at these statementsThe WinWait("The ....") will wait forever for the existance of the window with your title adding a timeout would prevent that ..WinWait ( "title" [, "text" [, timeout]] )The WinWaitActive("The ....") will wait forever till the windows get the Focus (is activated) ... to avoid that you could also add a timeout. WinWaitActive ( "title", ["text"], [timeout] ) SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Wallfire Posted March 3, 2004 Author Share Posted March 3, 2004 JdeB, i know it didnt make sense why it was causing me to hybernate either. it happens so quick it iwas hard to tell what was going on, i saw the script acces the start menu but i couldnt see why it selected. im asssuming it clicked on something that makes my comp wanna hybernate [im using XP] what i do know is i took out that part of code and the problem stoped occuring. anyways, i got my first scipt up and running now, anyone wanna see my code? perhaps let me know if i could code in a 'smarter' fashion?? :cheer: awww...wheres the chick? Link to comment Share on other sites More sharing options...
Developers Jos Posted March 3, 2004 Developers Share Posted March 3, 2004 Then it must have been this statement Opt("MouseCoordMode",0)since that determines where the mouseclick are done that are part of the rest of the program. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Wallfire Posted March 4, 2004 Author Share Posted March 4, 2004 hey, me again. im trying to do similar things now with a popup window. i want the window to show 2 numbers that the program calculated. would the following work? $text="X=" & $x & " Y=" & $y MsgBox(4096, "Point Found", text, 2) :cheer: awww...wheres the chick? Link to comment Share on other sites More sharing options...
CyberSlug Posted March 4, 2004 Share Posted March 4, 2004 Make sure to put a $ in front of text.MsgBox(4096, "Point Found", $text) Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
Wallfire Posted March 4, 2004 Author Share Posted March 4, 2004 Make sure to put a $ in front of text.heh, yup. i forgot about that guy... thanks for your help! here is my latest Q: when i use the PixelGetColor command the mouse seems to move where it is supposed to be looking, making the process slow down. i want to be able to scan a picute untill i find a certain pixel combonation and if the program has to move the mouse in 10 pixel increments...its gonna take a loooong time to scan the picture. is there a reason why the PixelGetColor command moves the mouse? or is my coding somehow making it move. what can i do to make the process faster? here is a code snip-let: (sorry about the lack of comments, if it is un-readable ill repost with proper documentation...) while 1 for $x = $Xstart To $Xstop step 10 for $y= $Ystart To $Ystop step 10 $ChickenTest = ChickenTest($x,$y) If $ChickenTest = 1 Then MouseClick("left",$x,$y) EndIf Next Next WEnd Func ChickenTest($x,$y) $Result = 1;False untill proven true $PixLevelOne = PixelGetColor($x,$y) If $PixLevelOne = 14606302 Then MouseMove($x,$y) sleep(100) MsgBox(4096, "Last Point:", "LevelOne Pass") $PixLevelTwo = PixelGetColor(266,254) If $PixLevelTwo = 65535 Then $Result = 1 $text="X=" & $x & " Y=" & $y MsgBox(4096, "Point Found", $text, 2) EndIf EndIf Return $Result EndFunc hmm, maybe GetPixelColor doesnt move the cursor...i just ran the code in a diffrent picure and the thing went crazy, clicking on every (x,y) location. argh! here is the logic that i want the code to preform: 1)scan a area 2) if a pixel in that area is white (14606302) it passes levelone test 3) check to see if it passes leveltwo test by: move the mouse to (x,y) and look at pixel #(266,254) if that is yellow then it is the right spot. the program should click and pop up a menu. 4)if it does not find a spot it will keep scanning :cheer: awww...wheres the chick? Link to comment Share on other sites More sharing options...
Valik Posted March 4, 2004 Share Posted March 4, 2004 $Result = 1;False untill proven true That should be $Result = 0. Anything non-zero is true, 0 is false. This is causing the return value to ALWAYS be true, and thus, your MouseClick line executes every time. Link to comment Share on other sites More sharing options...
Wallfire Posted March 4, 2004 Author Share Posted March 4, 2004 (edited) wow, i feel stupid...found the error: $Result = 1;False untill proven true it should be =0 untill proven 1. such a silly mistake... anyway, i got it scaning MUCH faster now, man i love autoit!!! Edit: wow, im even more stupid. i didtn see Valik's response at all! lol, thanks alot man. its helpful to have a second pair of eyes look at the code. it took me 3 hours to find that mistake... Edited March 5, 2004 by Wallfire :cheer: awww...wheres the chick? Link to comment Share on other sites More sharing options...
Wallfire Posted March 5, 2004 Author Share Posted March 5, 2004 mods: is it ok for me to keep asking my newb questions in the same thread? i am trying to keep the clutter to a min.hey everyone, me again i got my code working fairly good now. here is a background of my code and what it does:While 11)scan an area [on the screen]2) if a pixel in that area is white (14606302) it passes levelone test3) check to see if it passes leveltwo test by: move the mouse to (x,y) and look at pixel #(266,254) if that is yellow then it is the right spot. the program should click.4)if it does not find a spot it will keep scanning WEndat first i was using a MouseMove command and checking the pixel color underneath the cursor to scan the area. this was WAY too slow.my second just scanned the area without moving the cursor which made it run MUCH faster.BUT [there is always a but...] i need it to go faster still. as it is now i am scanning the area in 6 seconds [450pixelsX300pixels]. i would like to take this down to 2-3 seconds.i assume that this could be achieved by how 'efficient' my code is. like how many lines of code total, what kind of loops, how much time is spent in each loop, how many repeated tasks does it do, etc...right now i have lots of while loops, if, and for loops. i think the while loops take alot of processor time to complete. if i were to somehow re-word the coding into a for loop or if loop, would the speed increase/decrease? [or vise-versa]if i use more functions would that help reduce the time it takes to make one pass of the area? does the overall size of the code in lines have any effect on time to compete? what are some pointers to help with speed? i would post my code but as of now it is pretty 'rough' maybe once i add in some comments ill post it so that people can actually follow my madness. :cheer: awww...wheres the chick? Link to comment Share on other sites More sharing options...
GrahamS Posted March 5, 2004 Share Posted March 5, 2004 (edited) Just some quick thoughts. First, I hope that you are using MouseMove($x,$y,0) The third parameter is the speed which from the help file [optional]the speed to move the mouse in the range 1 (fastest) to 100 (slowest). A speed of 0 will move the mouse instantly. Default speed is 10.Secondly I don't think that a while loop would be slower than a for loop. Functions have a slight overhead associated with them (they need to perform some entry code and then some exit code). So adding functions will actually slow things down slightly. Inlining functions would speed up the code, but makes it harder to read. One performance improvement with functions is to pass parameters by reference. If the parameters are large then this could be taking a fair amount of time. To explain, consider the following function Func MyFunction($a) ; do something EndFunc When the function is called then a copy of the parameter is made. If $a contains an integer then the performance hit is miniscule. However if the parameter contains a long string or array of bytes then performance could be hit if a lot of function calls were made. The answer is to pass the parameter by reference. This is done by adding the ByRef keyword to the function definition as follows Func MyFunction(ByRef $a) ; do something EndFunc This stops AutoIt performing the copy. The drawback (TINSTAAFL) is that the parameter passed to MyFunction must be a variable. So MyFunction("This is a string") ; failure $temp = "This is a string" MyFUnction($temp) ; OK Finally, remember that the big performance gains come not from doing things faster but by doing less. Changing to a faster algorithm or a better way of doing things will gain a lot more than tinkering with the code. For instance, you're searching 450pixels X 300pixels Is it equally likely that what you want is anywhere in this area. If it is most likely to be in the middle of the artea, then search there first - if you find that it isn't there then search a little further out. Keep on going until you find it. Now this would slightly increase the time taken if the pixel you want is right at the outside of the area, but on average would speed up the search Edited March 5, 2004 by GrahamS GrahamS Link to comment Share on other sites More sharing options...
Wallfire Posted March 5, 2004 Author Share Posted March 5, 2004 yes i am using mouseclick, but that is not where speed loss is coming from. once i have 'clicked' the process has been considered succesful. i need more speed out of the searching method... hmm...functions are bad huh? i am only using 2 fuctions in the search process and they are both used at every (x,y) location. their inputs are all variables ($x,$y) both are pretty small variables only 3 digits per var. i like your idea of starting the search in the middle. this would actually speed things up a bit quite nicely, if i could get the (x,y) to spiral out from a base center i think things would work better. i have thought about this in the past but couldnt think of a easy of making in spiral, ill put some more time into in later this week. it shouldnt be TOO hard...it will just take some thinking. here is my code with alot of the lines taken out so it is not so long. check out lines 0085 and 0102, is there a better way of doing this? does my overall logic for the code make sense? line 0126--- why wont this work? i wanted to make it so that if i hit F2 it would add 50 to the $WaitCount var, it never seemed to work while running the code. expandcollapse popup0020 +-While 1 0021 | +-For $X = $XSTART To $XSTOP Step 10 0022 | | +-For $Y= $YSTART To $YSTOP Step 10 0023 | | | 0024 | | | $CHICKENTEST = ChickenTest($X,$Y) 0025 | | | +-If $CHICKENTEST = 1 Then 0026 | | | | MouseClick("left",$X,$Y) 0027 | | | | Sleep(4100) 0031 | | | | 0032 | | | +-EndIf;chicken if 0033 | | | $FEATHERTEST = FeatherTest($X,$Y) 0034 | | | +-If $FEATHERTEST = 1 Then 0035 | | | | MouseClick("left",$X,$Y) 0036 | | | | Sleep(1000) 0039 | | | | 0040 | | | +-EndIf;feather IF 0041 | | | 0042 | | | +-If $WAITCOUNT> 10 Then 0043 | | | | ;stuff in here is kinda long/messy, i took it out 0074 | | | +-EndIf 0075 | | +-Next 0076 | +-Next 0077 | 0078 | $WAITCOUNT=$WAITCOUNT + 1 0079 | 0080 +-Wend 0081 0082 +-Func ChickenTest($X,$Y) 0083 | $RESULT = 0;False untill proven true 0084 | $PIXLEVELONE = PixelGetColor($X,$Y) 0085 | +-If $PIXLEVELONE = 14606302 Or $PIXLEVELONE = 16250871 Or $PIXLEVELONE = 41703 Or $PIXLEVELONE = 10263196 Or $PIXLEVELONE =239 Or $PIXLEVELONE = 12435133 Then 0086 | | ;MsgBox(4096, "Chicken ColorPoint:",$PixLevelOne, 1) 0087 | | 0088 | | MouseMove($X,$Y,1) 0089 | | $PIXLEVELTWO = PixelGetColor(297,222) 0090 | | +-If $PIXLEVELTWO = 65535 Then 0091 | | | $RESULT = 1;then true 0092 | | +-EndIf 0093 | +-EndIf 0094 | 0095 | 0096 | Return $RESULT 0097 +-EndFunc ;==>ChickenTest 0098 +-Func FeatherTest($X,$Y) 0099 | $RESULT = 0;False untill proven true 0100 | $PIXLEVELONE = PixelGetColor($X,$Y) 0101 | 0102 | +-If $PIXLEVELONE = 8685188 Or $PIXLEVELONE = 12434109 Then 0103 | | MouseMove($X,$Y,1) 0104 | | $PIXLEVELTWO = PixelGetColor(253,217) 0105 | | +-If $PIXLEVELTWO = 4363007 Then 0106 | | | $RESULT = 1;then true 0107 | | +-EndIf 0108 | +-EndIf 0109 | Return $RESULT 0110 +-EndFunc ;==>FeatherTest 0111 0112 0113 +-Func Terminate() 0123 | Exit 0 0124 +-EndFunc ;==>Terminate 0125 0126 +-Func GetLost() 0127 | $WAITCOUNT=$WAITCOUNT + 50 0128 +-EndFunc ;==>GetLost 0129 :cheer: awww...wheres the chick? Link to comment Share on other sites More sharing options...
Developers Jos Posted March 5, 2004 Developers Share Posted March 5, 2004 line 0126--- why wont this work? i wanted to make it so that if i hit F2 it would add 50 to the $WaitCount var, it never seemed to work while running the code. Whenyou have this statement at the top of your script it should work fine :HotKeySet ( "{F2}" , "GetLost")You could, for testings purpose, put a MsgBox(4092,'debug', '$WAITCOUNT:' & $WAITCOUNT) statement after line 127... just to see if the F2 works.... SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now