j0kky Posted November 19, 2016 Posted November 19, 2016 (edited) Hi guys, talking about array in array, I would like to directly assign a value to an element in an array contained in another array. While it is quite simple to access the value if it is already setted: Local $a[3] = [1, 2], $b[2] = [3, 4] $a[2] = $b ConsoleWrite(($a[2])[0] & " " & ($a[2])[1] & @CRLF) If I try to write directly to the element, I get an error: Local $a[3] = [1, 2] Local $b[2] $a[2] = $b ($a[2])[0] = 1 Is assigning first every value of the contained array and then including it in the container the only way? Edited November 19, 2016 by j0kky Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs
UEZ Posted November 19, 2016 Posted November 19, 2016 (edited) You need a helper function with ByRef parameter. Simple example: #include <Array.au3> Local $a[3] = [1, 2], $b[2] = [3, 4] $a[2] = $b ConsoleWrite(($a[2])[0] & " " & ($a[2])[1] & @CRLF) ModArray($a[2], 0, "Test") _ArrayDisplay($a[2]) Func ModArray(ByRef $aArray, $iElement, $value) $aArray[$iElement] = $value EndFunc Otherwise a copy of the array will be created. Edited November 19, 2016 by UEZ j0kky 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
j0kky Posted November 20, 2016 Author Posted November 20, 2016 Thank you for support! Writing a function with a ByRef param is a smart solution, anyhow it could be useful to directly assign the value to the element. I'll open a feature request in the bug tracker, maybe in some of the next Autoit version it will be implemented. Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs
UEZ Posted November 20, 2016 Posted November 20, 2016 3 hours ago, j0kky said: I'll open a feature request in the bug tracker, maybe in some of the next Autoit version it will be implemented. Soon is christmas, I would suggest to send the feature list rather to Santa Claus. Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
j0kky Posted November 20, 2016 Author Posted November 20, 2016 LoL Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs
trancexx Posted November 20, 2016 Posted November 20, 2016 On 19.11.2016. at 3:29 PM, j0kky said: Hi guys, talking about array in array, I would like to directly assign a value to an element in an array contained in another array. While it is quite simple to access the value if it is already setted: Local $a[3] = [1, 2], $b[2] = [3, 4] $a[2] = $b ConsoleWrite(($a[2])[0] & " " & ($a[2])[1] & @CRLF) If I try to write directly to the element, I get an error: Local $a[3] = [1, 2] Local $b[2] $a[2] = $b ($a[2])[0] = 1 Is assigning first every value of the contained array and then including it in the container the only way? What error? If you see error, then it's not by AutoIt because your code is perfectly valid. It's only that the lase line is not an assignment. There is no error. ♡♡♡ . eMyvnE
j0kky Posted November 20, 2016 Author Posted November 20, 2016 (edited) 5 minutes ago, trancexx said: It's only that the lase line is not an assignment. ($a[2])[0] = 1 The problem is exatly that this line is not considered as an assignment, but ($a[2])[0] is correctly parsed when you try to read from it. Edited November 20, 2016 by j0kky Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs
kylomas Posted November 20, 2016 Posted November 20, 2016 @trancexx, Given local $a = [1,2,3], $b = ['a','b','c'], $c = [$a,$b] how would you change the "a" in array $c? kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
trancexx Posted November 20, 2016 Posted November 20, 2016 1 hour ago, j0kky said: ($a[2])[0] = 1 The problem is exatly that this line is not considered as an assignment, but ($a[2])[0] is correctly parsed when you try to read from it. In both cases you read from it. That's the whole thing. ♡♡♡ . eMyvnE
trancexx Posted November 20, 2016 Posted November 20, 2016 13 minutes ago, kylomas said: @trancexx, Given local $a = [1,2,3], $b = ['a','b','c'], $c = [$a,$b] how would you change the "a" in array $c? kylomas Just like UEZ did. ♡♡♡ . eMyvnE
j0kky Posted November 20, 2016 Author Posted November 20, 2016 (edited) 1 hour ago, trancexx said: In both cases you read from it. That's the whole thing. Yes, now it is clear, but it sounds strange to me because if you declare a simple array and try to do the same thing, Autoit doesn't read from it but assigns to it the value. Local $a[2] $a[0] = 1 Edited November 20, 2016 by j0kky Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs
trancexx Posted November 20, 2016 Posted November 20, 2016 28 minutes ago, j0kky said: Yes, now it is clear, but it sounds strange to me because if you declare a simple array and try to do the same thing, Autoit doesn't read from it but assigns to it the value. Local $a[2] $a[0] = 1 That's because you're showing different case. What you did earlier was more like this: Local $a[2] ($a[0]) = 1 What does this do? ♡♡♡ . eMyvnE
trancexx Posted November 20, 2016 Posted November 20, 2016 Don't read wrong what I say, I'm just explaining what AutoIt does. I wrote the code, so I would know. However I did left it in beta stage, and afterward Jon decided he'd release it. I would ask... but he did not :). ♡♡♡ . eMyvnE
j0kky Posted November 20, 2016 Author Posted November 20, 2016 (edited) No problem @trancexx, I'm here to learn I'll try to pose the issue in another way (but I think you already get my point): If I'm working with a simple array: Local $a[2] $a[0] = 1 ConsoleWrite(($a)[0] & @CRLF) ConsoleWrite($a[0] & @CRLF) ConsoleWrite outputs are identical. But if I'm dealing with an array into an array: Local $a[3] = [1, 2], $b[2] = [3, 4] $a[2] = $b ConsoleWrite(($a[2])[0] & @CRLF) ConsoleWrite($a[2][0] & @CRLF) The second one (obviously) returns an error because it searches for the 2nd dimension of $a. Edited November 20, 2016 by j0kky Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs
j0kky Posted November 21, 2016 Author Posted November 21, 2016 In other words, it could be useful if the syntax: (array)[element] wasn't used only for reading, but for assigning too: (array)[element] = value Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs
kovlad Posted April 21, 2021 Posted April 21, 2021 I published my function for nested arrays based on the idea of UEZ. https://www.autoitscript.com/forum/topic/205675-nested-arrays/
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