Jump to content

Recommended Posts

#include "Array.au3"

ArrayInArrayTest()

Func ArrayInArrayTest()
    Local $Array[][] = [ [1,2,3], [4,5,6], [7,8,9] ]
    Local $ArrayInArray[] = [ $Array ]
    _ArrayDisplay($ArrayInArray, "ArrayInArray")
    _ArrayDisplay($ArrayInArray[0], "ArrayInArray[0]")
    ($ArrayInArray[0])[0][0] += 1 ;<-- syntax error
EndFunc

I am trying to increase value in 2D array cell but this array is in another array and I got syntax error. I have no idea how to fix this. Any idea?

I could not find any information about this in this article:

https://www.autoitscript.com/wiki/Arrays

 

Edit: After wiriting this post I found a solution. Not sure if this is right but it works:

#include "Array.au3"

ArrayInArrayTest()

Func ArrayInArrayTest()
    Local $Array[][] = [ [1,2,3], [4,5,6], [7,8,9] ]
    Local $ArrayInArray[] = [ $Array ]
    _ArrayDisplay($ArrayInArray, "ArrayInArray")
    _ArrayDisplay($ArrayInArray[0], "ArrayInArray[0]")
    $aTempArray = $ArrayInArray[0]
    $aTempArray[0][0] += 1
    $ArrayInArray[0] = $aTempArray
    _ArrayDisplay($ArrayInArray[0], "ArrayInArray[0]")
EndFunc

 

Edited by maniootek
Link to post
Share on other sites

But usually it is better to create a function to help modifying the inner array :

#include <Constants.au3>
#include "Array.au3"

ArrayInArrayTest()

Func ArrayInArrayTest()
    Local $Array[][] = [ [1,2,3], [4,5,6], [7,8,9] ]
    Local $ArrayInArray[] = [ $Array ]
    _ArrayDisplay($ArrayInArray, "ArrayInArray")
    _ArrayDisplay($ArrayInArray[0], "ArrayInArray[0]")
    ModifyArray ($ArrayInArray[0], 0, 0, 1)
    _ArrayDisplay($ArrayInArray[0], "ArrayInArray[0]")
EndFunc

Func ModifyArray(ByRef $aArray, $x, $y, $v)
  $aArray[$x][$y] += $v
EndFunc

 

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...