Jump to content
Sign in to follow this  
AlmarM

Initialize a 2D array with predefined 1D arrays as values

Recommended Posts

AlmarM

Hi!

Is AutoIt able to initialize a 2D array with predefined values as arrays? I can't seem to make it work without a workaround.

In this example the 2D array takes the predefined values as regular values, while I want them to be 1D arrays.

#include <Array.au3>

Global $asBegin[3][1] = [["a1-1"],["a1-0"],["a0-1"]]
_ArrayDisplay($asBegin)

 

In this example the 2D array does take the predefined arrays as array, because I defined them in another function.

#include <Array.au3>

Global $asBegin[3][1] = [[__MA("a1-1")],[__MA("a1-0")],[__MA("a0-1")]]
_ArrayDisplay($asBegin)
_ArrayDisplay($asBegin[1][0])

Func __MA($sString)
    Local $asResult[1] = [$sString]
    Return $asResult
EndFunc

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
Melba23

AlmarM,

If you want to place an array inside another array you need to declare the internal array first and then add it as an element of the container array. But you can read the elements of the internal array directly - see the latest Beta Help file <Language Reference - Variables - Data types in Arrays> (I have just rewritten it). :)

M23

  • Like 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
jchd

Your example is essentially 1D: declaring $a[3][1] is essentially equivalent to declaring it $a[3], it just makes accessing the array element uselessly convoluted and slow.

Similarly declaring $a[1] is essentially equivalent to $a.

Then AutoIt doesn't support array literals, so your first syntax doesn't produce what you expect it to.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
AlmarM

Your example is essentially 1D: declaring $a[3][1] is essentially equivalent to declaring it $a[3], it just makes accessing the array element uselessly convoluted and slow.

Similarly declaring $a[1] is essentially equivalent to $a.

Then AutoIt doesn't support array literals, so your first syntax doesn't produce what you expect it to.

 

Yes, I get that. :)

These are just samples to reproduce the issues I stumbled upon. I'm still experimenting with the way I'd like to go in the end. Thanks!


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
jchd

Just keep in mind that nested arrays are much slower and uncomfortable to work with than higher-dimensional arrays.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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  

×