Jump to content

Error with pixelsearch for loop


cageman
 Share

Recommended Posts

dim $slot, $totsslots

For $i = 2 to $totslots+1

$slot[$i]=PixelSearch(777,350+18*($i-1),778,850,0x000000)

Next

looks the error comes from the $slot[$i] subscript used with non-array variable is the error

any1 got a solution for this loop so it works like its supposed to?

thx!

Link to comment
Share on other sites

you are only declaring $slot as a variable, not as an array, u need to first declare it as an array and then if need be redim it in your loop to increase size on the fly (or atleast thats how i do it). $totslots is also misspelled.

EG:

#include<Array.au3>

dim $slot[2],$totsslots
$slot[0] = 1
$totsslots = 5

For $i = 1 to $totsslots+1
    If $i > $slot[0] then 
        redim $slot[$i+1]
        $slot[0] = $i
    EndIf
    $slot[$i]=PixelSearch(777,350+18*($i-1),778,850,0x000000)
Next

_ArrayDisplay($slot)
Edited by ofLight

There is always a butthead in the crowd, no matter how hard one tries to keep them out.......Volly

Link to comment
Share on other sites

you are only declaring $slot as a variable, not as an array, u need to first declare it as an array and then if need be redim it in your loop to increase size on the fly (or atleast thats how i do it). $totslots is also misspelled.

EG:

#include<Array.au3>

dim $slot[2],$totsslots
$slot[0] = 1
$totsslots = 5

For $i = 1 to $totsslots+1
    If $i > $slot[0] then 
        redim $slot[$i+1]
        $slot[0] = $i
    EndIf
    $slot[$i]=PixelSearch(777,350+18*($i-1),778,850,0x000000)
Next

_ArrayDisplay($slot)

very nice:) works

never worked with arrays before, but why do i need to redim each array? thats always needed?

Link to comment
Share on other sites

ReDim allows you to change the size of the array without loseing any of the data. You don't need to do this if you already know the total size the array needs to be, in that case you could just Dim $array[$maxsize]. Using the Redim in the above script allows your array size to be dynamic no matter how big you need it.

Edited by ofLight

There is always a butthead in the crowd, no matter how hard one tries to keep them out.......Volly

Link to comment
Share on other sites

very nice:) works

never worked with arrays before, but why do i need to redim each array? thats always needed?

now even harder...

i need a double loop.

what i want is this:

first go from x coordinate 1 to 10 and check the colors there then go 1 lower and repeat this 5 times. you get 10*5 coordinates then.

these coordinates need to be stored in order so from the x=1 y=1 to x=10 y=5

I tried this below:

Func item($sloti)
Dim $welkepixel, $welkepixel[10][5], $letterstring,
$welkepixel[0][0]=1

For $b = 1 to 10
For $a = 1 to 5 
$welkepixel[$b][$a]=PixelGetColor($sloti[0]+$b,$sloti[1]+$a)
If $welkepixel[$b][$a]=0x000000 Then
$letterstring=$letterstring & 1
Else
$letterstring=$letterstring & 0
EndIf
Next
Next
_ArrayDisplay($welkepixel)

Endfunc

edit:

no errors anymore. i should have dimmed: $welkepixel[11][6] :)

thx for the help!

Edited by cageman
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...