AlmarM Posted July 27, 2014 Share Posted July 27, 2014 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. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 27, 2014 Moderators Share Posted July 27, 2014 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 AlmarM 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jchd Posted July 27, 2014 Share Posted July 27, 2014 (edited) 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 July 27, 2014 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 hereRegExp tutorial: enough to get startedPCRE 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) Link to comment Share on other sites More sharing options...
AlmarM Posted July 27, 2014 Author Share Posted July 27, 2014 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. Link to comment Share on other sites More sharing options...
jchd Posted July 27, 2014 Share Posted July 27, 2014 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 hereRegExp tutorial: enough to get startedPCRE 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) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now