Sign in to follow this  
Followers 0
AlmarM

Creating a 2D Array

4 posts in this topic

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.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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.

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