XZ3R0 Posted February 19, 2009 Share Posted February 19, 2009 In short: how can i find the velocity of an object? Right now i have 2 pixelseraches that i plug into the formula of velocity. But once i run the second search the first one gets forgotten. So whats a work around or another way to find the velocity of an object. Another problem i thought about is if the pixelsearch doesn't find the same object the second time. this would return with unusable data. In long: i have an array of 3 colors im searching for. I run the first pixel search. lets say it finds black. then i runs a second pixlesearch. it also finds the same black. then i get the velocity and i do what i need with it. that's my theory. but what if during the second pixelsearch it finds red instead (a different object) then the formula isn't going to work. is there a way to track an object? or even search around the same area as before but for the same color? do i need to set the returned values for the pixlesearch in an array? or should i be using something completely different? Link to comment Share on other sites More sharing options...
GrungeRocker Posted February 19, 2009 Share Posted February 19, 2009 "But once i run the second search the first one gets forgotten." Using the same var? [font="Verdana"]In work:[list=1][*]InstallIt[*]New version of SpaceWar[/list] [/font] Link to comment Share on other sites More sharing options...
XZ3R0 Posted February 19, 2009 Author Share Posted February 19, 2009 (edited) no. one is $search = pixelsearch(...) and the other one is $search2 = pixelsearch(...) then if i used $search[0] the script will run into an error and say something about a non arrayed variable trying to be use as a array. Edited February 19, 2009 by XZ3R0 Link to comment Share on other sites More sharing options...
GrungeRocker Posted February 19, 2009 Share Posted February 19, 2009 Just seems like the first one does not find anything. Try to check it with IsArray() or UBound() (IsArray would be better in this case) [font="Verdana"]In work:[list=1][*]InstallIt[*]New version of SpaceWar[/list] [/font] Link to comment Share on other sites More sharing options...
XZ3R0 Posted February 19, 2009 Author Share Posted February 19, 2009 the second one only runs if not @error. i do not get the error until AFTER the second one is ran. Link to comment Share on other sites More sharing options...
GrungeRocker Posted February 19, 2009 Share Posted February 19, 2009 It would be easier with you posting a sample source.... [font="Verdana"]In work:[list=1][*]InstallIt[*]New version of SpaceWar[/list] [/font] Link to comment Share on other sites More sharing options...
XZ3R0 Posted February 19, 2009 Author Share Posted February 19, 2009 $coor1 = PixelSearch( $start[0], $start[1], $current[0], $current[1], $Colors, 5, 8 ) While Not @error $time = TimerInit() $coor2 = PixelSearch( $start[0], $start[1], $current[0], $current[1], $Colors, 5, 8 ) $velocityx = ($coor1[0] - $coor2[0])/TimerDiff($time) $velocityy = ($coor1[1] - $coor2[1])/TimerDiff($time) MouseClick ( "left", (($velocityx*timerdiff($time))+400), (($velocityy*TimerDiff($time))+470), 1, 3 ) Sleep(500) Link to comment Share on other sites More sharing options...
GrungeRocker Posted February 19, 2009 Share Posted February 19, 2009 $coor1 = PixelSearch( $start[0], $start[1], $current[0], $current[1], $Colors, 5, 8 ) While Not @error $time = TimerInit() $coor2 = PixelSearch( $start[0], $start[1], $current[0], $current[1], $Colors, 5, 8 ) if IsArray($coor1) And IsArray($coor2) Then $velocityx = ($coor1[0] - $coor2[0])/TimerDiff($time) $velocityy = ($coor1[1] - $coor2[1])/TimerDiff($time) MouseClick ( "left", (($velocityx*timerdiff($time))+400), (($velocityy*TimerDiff($time))+470), 1, 3 ) EndIf Sleep(500) Try this [font="Verdana"]In work:[list=1][*]InstallIt[*]New version of SpaceWar[/list] [/font] Link to comment Share on other sites More sharing options...
XZ3R0 Posted February 19, 2009 Author Share Posted February 19, 2009 (edited) so it works now but the velocity thing doesn't. probably because the objects are restricted to a box or something :\ edit: ok, my velocity formula was backwards should be coord2-coord1 but it still doesn't work. Edited February 19, 2009 by XZ3R0 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