Jump to content

Creating a 2D Array


Recommended Posts

Hiya!

I tried making a 2DArray in autoit and im confused now. Could someone help me a hand? :P

#include <Array.au3>

Global $Array[10, 10] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
                        [1, 0, 0, 0, 0, 0, 0, 0, 0, 1],
                        [1, 0, 0, 0, 0, 0, 0, 0, 0, 1],
                        [1, 0, 0, 0, 0, 0, 0, 0, 0, 1],
                        [1, 0, 0, 0, 0, 0, 0, 0, 0, 1],
                        [1, 0, 0, 0, 0, 0, 0, 0, 0, 1],
                        [1, 0, 0, 0, 0, 0, 0, 0, 0, 1],
                        [1, 0, 0, 0, 0, 0, 0, 0, 0, 1],
                        [1, 0, 0, 0, 0, 0, 0, 0, 0, 1],
                        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
                       
_ArrayDisplay($Array)

AlmarM :mellow:

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

Global $Array[7][10] = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],[1, 0, 0, 0, 0, 0, 0, 0, 0, 1],[1, 0, 0, 0, 0, 0, 0, 0, 0, 1],[1, 0, 0, 0, 0, 0, 0, 0, 0, 1],[1, 0, 0, 0, 0, 0, 0, 0, 0, 1],[1, 0, 0, 0, 0, 0, 0, 0, 0, 1],[1, 0, 0, 0, 0, 0, 0, 0, 0, 1]]
_ArrayDisplay($Array)

Edited by Juvigy
Link to comment
Share on other sites

You use a underscore to continue lines.

Here's how it should look:

#include <Array.au3>

Global $Array[10][10] = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], _
                        [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], _
                        [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], _
                        [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], _
                        [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], _
                        [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], _
                        [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], _
                        [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], _
                        [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], _
                        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]

_ArrayDisplay($Array)

If you think the helpfile isn't very good at teaching arrays, there's a tutorial in the wiki LINK

Link to comment
Share on other sites

Found. :party:

#include <Array.au3>

Global $Array[10][10] = [   [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], _
                            [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], _
                            [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], _
                            [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], _
                            [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], _
                            [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], _
                            [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], _
                            [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], _
                            [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], _
                            [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]  ]
                       
_ArrayDisplay($Array)

Thanks Juvigy.

EDIT: Oh, didn't saw AdmiralAlkex's post. :mellow:

EDIT: So why isn't this working?

#include <Array.au3>

Global $Array[10][10] = [   [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], _
                            [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], _
                            [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], _
                            [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], _
                            [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], _
                            [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], _
                            [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], _
                            [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], _
                            [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], _
                            [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]  ]

$GUI = GUICreate("", 320, 320)

For $y = 0 To 10
    For $x = 0 To 10
        If ($Array[$y][$x] == 0) Then
            GUICtrlCreatePic(@DesktopDir & "\floor.jpg", $x * 32, $y * 32, 32, 32)
        EndIf
        
        If ($Array[$y][$x] == 1) Then
            GUICtrlCreatePic(@DesktopDir & "\wall.jpg", $x * 32, $y * 32, 32, 32)
        EndIf
        
        If ($Array[$y][$x] == 2) Then
            GUICtrlCreatePic(@DesktopDir & "\prop.jpg", $x * 32, $y * 32, 32, 32)
        EndIf
        
        If ($Array[$y][$x] == 3) Then
            GUICtrlCreatePic(@DesktopDir & "\player.jpg", $x * 32, $y * 32, 32, 32)
        EndIf
    Next
Next

GUISetState()
While 1
    Switch GUIGetMsg()
    Case -3
        Exit
    EndSwitch
WEnd

C:\Documents and Settings\--\Bureaublad\Nieuw - AutoIt v3 Script.au3 (18) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
If ($Array[$y][$x] == 0) Then
If (^ ERROR

Found it. :P

Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

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...