Sign in to follow this  
Followers 0
gamerman2360

Declaring large 2D arrays

5 posts in this topic

I have made a function that writes 2D arrays so that they can be declaired in an autoit script. It works for small arrays but when you get into the arrays that are about 100 and such it stops working. The error says there is a bracket in the wrong place or something... Can someone please see what the problem is. Examples are in the script. I tried to comment as much as I can to explane.

Global $array1[2][2] = [[1, "2"], ["3", 4]]; make a small array

Global $array2[100][100]; make a big array for the example
For $y = 0 To UBound($array2, 2) - 1
    For $x = 0 To UBound($array2) - 1
        $array2[$x][$y] = PixelGetColor($x, $y)
    Next
Next

MsgBox(0, "Test", _Write2DArray("array1", $array1)); it works here, trust me
ClipPut(_Write2DArray("array", $array2)); something went bad here, lots of text, use an editor to view

Func _Write2DArray($arrayname, $array, $mode = 0); the function
    $ExpandVarStrings = Opt("ExpandVarStrings", 1); Need this
    If $mode = 1 Then; Which way to declare it
        $mode = "Global"
    ElseIf $mode = 2 Then; 1 for global, 2 for local, anything else or blank makes it dim
        $mode = "Local"
    Else
        $mode = "Dim"
    EndIf
    $newarray = $mode & " $" & $arrayname & "[" & UBound($array) & "][" & UBound($array, 2) & "] = ["; Start it off
    For $x = 0 To UBound($array) - 1; Loop through x
        If $x Then $newarray &= ", _@CRLF@@TAB@@TAB@@TAB@"; If it's not the first, add a comma and start a new line
        $newarray &= "["; Start a group
        For $y = 0 To UBound($array, 2) - 1; Loop through y
            If $y Then $newarray &= ", "; If it's not the first, add a comma
            If IsString($array[$x][$y]) Then $newarray &= """"; If it is a string it needs a start quote
            $newarray &= $array[$x][$y]; Add the data
            If IsString($array[$x][$y]) Then $newarray &= """"; If string, end quote
        Next; end for
        $newarray &= "]"; End the group
    Next; end for
    $newarray &= "]"; Close it off
    Opt("ExpandVarStrings", $ExpandVarStrings); Change the opt back
    Return $newarray
EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I take it this is not the out put your looking for?

Edit:

Too much information for codebox, here's the txt file:

Edit2:

Never Mind... I see what your saying.

: ==> Missing right bracket ')' in expression.:

You think reaching the 409x character line limit has something to do with it?

Edit3:

I get 97,700 characters for the string length which is fine, but

Maximum string length is 2147483647 characters (but keep in mind that no line in an AutoIt script can exceed 4095 characters.)

Is why I was wondering...
Global $array1[2][2] = [[1, "2"], ["3", 4]]; make a small array

Global $array2[90][90]; make a big array for the example
For $y = 0 To UBound($array2, 2) - 1
    For $x = 0 To UBound($array2) - 1
        $array2[$x][$y] = '0x' & Hex(PixelGetColor($x, $y), 6)
    Next
Next

ConsoleWrite(_Write2DArray("array1", $array1)); it works here, trust me
ClipPut(_Write2DArray("array", $array2)); something went bad here, lots of text, use an editor to view

Func _Write2DArray($arrayname, $array, $mode = 0); the function
    $ExpandVarStrings = Opt("ExpandVarStrings", 1); Need this
    If $mode = 1 Then; Which way to declare it
        $mode = "Global"
    ElseIf $mode = 2 Then; 1 for global, 2 for local, anything else or blank makes it dim
        $mode = "Local"
    Else
        $mode = "Dim"
    EndIf
    $newarray = $mode & " $" & $arrayname & "[" & UBound($array) & "][" & UBound($array, 2) & "] = ["; Start it off
    For $x = 0 To UBound($array) - 1; Loop through x
        If $x Then $newarray &= ", _ " & @LF & @TAB; If it's not the first, add a comma and start a new line
        $newarray &= "["; Start a group
        For $y = 0 To UBound($array, 2) - 1; Loop through y
            If $y Then $newarray &= ", "; If it's not the first, add a comma
            If IsString($array[$x][$y]) Then $newarray &= """"; If it is a string it needs a start quote
            $newarray &= $array[$x][$y]; Add the data
            If IsString($array[$x][$y]) Then $newarray &= """"; If string, end quote
        Next; end for
        $newarray &= "]"; End the group
    Next; end for
    $newarray &= "]"; Close it off
    Opt("ExpandVarStrings", $ExpandVarStrings); Change the opt back
    MsgBox(0, 'String Length', StringLen($newarray))
    Return $newarray
EndFunc
Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Dang, so that means to declare large arrays I need to do something like declare them 1 element per line? A 100x100 array is 1000 lines! Is there another way?

Share this post


Link to post
Share on other sites

Dang, so that means to declare large arrays I need to do something like declare them 1 element per line? A 100x100 array is 1000 lines! Is there another way?

I was thinking of indivudualizing them... I played with it a bit last night, but as you said, the lines were a bit ridiculous for each array. I just hope I'm wrong, and maybe someone else could shed some light on a 'better' way to do it.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

I guess you have to. A line can't more than 4000something characters like you said. Lol, i can picture using an entire #region to wrap it up in.

Share this post


Link to post
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
Sign in to follow this  
Followers 0