Jump to content

Problems with array vars


 Share

Recommended Posts

So I was tooling around trying to make a script that would find a window inside a game, not a seperate process, just like a chat window or an inventory window or however you want to imagine it. My problem is that once I set a variable to output of the pixelsearch function, I don't really understand how to get that information out of the array to put it to use. I can't put parts of the array into a regular variable, or parts of it into another array, so I tried just making a copy of it, and using that, but I can't slap a simple operator behind it to modify the information. I realize my script is pretty sloppy this is my first language and I've been writing it for like 48hrs.

Func winfin()
$winfinA = PixelSearch( 300, 300, 600, 500, 0x000000 , 0, 5 )
Sleep( 2000 )
MsgBox( 0 , $winfinA[0] , $winfinA[1] )


While @error = 0

$winfinx1 = $winfinA
$winfiny1 = $winfinA

$winfinx2 = $winfinx1
$winfinx2[0] += 6; this is where I have a problem, also when I try junk like this: $winfinx1 = $winfinA[0]

$winfiny2 = $winfiny1
$winfiny2[1] += 1

$winfinx1[0] += 1

$winfinA = PixelSearch( $winfinx1[0], $winfiny1[1], $winfinx2[0], $winfiny2[1], 0x000000 , 0, 1 )
Sleep( 1000 )
WEnd
$winfinx1[0] -= 21
$winfiny1[1] += 5
MsgBox( 0 , $winfinx1[1] , $winfiny2[0] )
EndFunc
HotKeySet( "f" , "winfin" )
While 1
    Sleep( 100 )
    WEnd
Link to comment
Share on other sites

I guess what I really want to know is it possible to put a single value from an array of values into a normal string or integer variable, and it is possible to use math operators on a single value in an array. I get errors when I try to do this in the ways pointed out in the OP.

Link to comment
Share on other sites

I guess what I really want to know is it possible to put a single value from an array of values into a normal string or integer variable, and it is possible to use math operators on a single value in an array. I get errors when I try to do this in the ways pointed out in the OP.

I'm not clear what you want to do with you function but I can imagine it is a bit confusing because $WinfinA is an array. You don't need to use arrays for the other variables, although you could, but I've changed your code to be what I think you want, but hopefully it makes sense to you.

Func winfin()
$winfinA = PixelSearch( 0, 0, 600, 500, 0x000000 , 0, 5 )
If @error = 1 Then ExitLoop
Sleep( 2000 )
MsgBox( 0 , $winfinA[0] , $winfinA[1] )


While 1

$winfinx1 = $winfinA[0] + 1
$winfiny1 = $winfinA[1]

$winfinx2 = $winfinxA[0] + 6

$winfiny2 = $winfinA[1] + 1


$winfinA = PixelSearch( $winfinx1, $winfiny1, $winfinx2, $winfiny2, 0x000000 , 0, 1 )
Sleep( 1000 )
WEnd
$winfinx1 -= 21
$winfiny1 += 5
MsgBox( 0 , $winfinx1 , $winfiny2 )
EndFunc
HotKeySet( "f" , "winfin" )
While 1
    Sleep( 100 )
    WEnd
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

The error I get with both your new function and my old one (before I tried using arrays to hold the new variables) is one that points to the $winfinA variable and tells me that I'm using a subscript with a non array variable. Maybe this is happening because the pixelsearch function fails after a number of loops and returns a non array variable variable? I'm not sure.

Edit: but I noticed that you added the 2nd pixelsearch function in at the bottom of the loop, and added an exit loop bit relating to the error, so if it fails it shoulden't try to use it anyhow. hm

Edited by Fluke
Link to comment
Share on other sites

The error I get with both your new function and my old one (before I tried using arrays to hold the new variables) is one that points to the $winfinA variable and tells me that I'm using a subscript with a non array variable. Maybe this is happening because the pixelsearch function fails after a number of loops and returns a non array variable variable? I'm not sure.

Edit: but I noticed that you added the 2nd pixelsearch function in at the bottom of the loop, and added an exit loop bit relating to the error, so if it fails it shoulden't try to use it anyhow. hm

Sorry, I was only changing the variables and didn't think about the logic. I didn't add the second pixelsearch, that was there in your OP.

This should be ok as far as errors go but since I don't understand what you're trying to do it probably does nothing very useful.

Func winfin()

    $winfinx1 = 0
    $winfiny1 = 0

    $winfinx2 = 600

    $winfiny2 = 500

    While 1
        $winfinA = PixelSearch( $winfinx1, $winfiny1, $winfinx2, $winfiny2, 0x000000 , 0, 1 )
        If @error = 0 Then;otherwise $winfinA is not an array
            $winfinx1 = $winfinA[0] + 1
            $winfiny1 = $winfinA[1]

            $winfinx2 = $winfinA[0] + 6

            $winfiny2 = $winfinA[1] + 1
        EndIf




        If @error = 1 Then ExitLoop; no black pixel found
    ;Sleep( 1000 )
    WEnd
    $winfinx1 -= 21
    $winfiny1 += 5
    MsgBox( 0 , $winfinx1 , $winfiny2 )
EndFunc
HotKeySet( "f" , "winfin" )
While 1
    Sleep( 100 )
WEnd
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Oh the idea is that I have windows inside a game window that have chat or something in them. I can color these windows a solid color, I was starting in on a script that would find that color, follow it to the top rightmost edge and then go back in a little bit and tell me that it had found the window. Obviously there should be some more checks to make sure that the first pixel if found was part of a window and not the background.

Link to comment
Share on other sites

martin, thanks so much. I got that part to work. Here it is fixed, I think the looping was my problem all along and I was misreading errors.

Opt( "MouseCoordMode" , 0 )
Opt( "PixelCoordMode" , 0 )

Func Winfin()
    $x1 = 45
    $y1 = 155
    $x2 = 1025
    $y2 = 655
    
    $a = PixelSearch(  $x1 , $y1 , $x2 , $y2 , 0x000000 , 0 , 5 )
    
    if @error = 0 Then
        
        While @error = 0
            $x1 = $a[0] + 1
            $y1 = $a[1]
            $x2 = $a[0] + 6
            $y2 = $a[1] + 1
            
            $a = PixelSearch(  $x1 , $y1 , $x2 , $y2 , 0x000000 , 0 , 1 )
        WEnd
        
        MouseMove( $x1, $y1 )
        
    EndIf
    
EndFunc

HotKeySet( "f" , "winfin" )

While 1
    Sleep( 100 )
WEnd
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...