Shaggi Posted October 8, 2011 Share Posted October 8, 2011 (edited) Suppose you have the following code: $Array = Array1() #cs Array Layout: $Array[0] = "one" $Array[1]: $Array2[0] = "Two" $Array2[1]: $Array3[0] = "Three" $Array3[1] = "Last element" #ce Func Array1() Local $Array[2] = ["one",Array2()] Return $Array EndFunc Func Array2() Local $Array[2] = ["two",Array3()] Return $Array EndFunc Func Array3() Local $Array[2] = ["Three","Last element"] Return $Array EndFuncWho is able to change the "Last element" in $Array to something else without creating a new copy of the original array and print it out? Edited October 8, 2011 by Shaggi Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG Link to comment Share on other sites More sharing options...
JohnOne Posted October 8, 2011 Share Posted October 8, 2011 Bill Gates. What do I win. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Shaggi Posted October 8, 2011 Author Share Posted October 8, 2011 Bill Gates. What do I win.This: Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG Link to comment Share on other sites More sharing options...
JohnOne Posted October 8, 2011 Share Posted October 8, 2011 Lovely, now the quiz winner is cleared up, I might have a pop at solving it myself. What do you regard as the "original array"? The global one, or one of those in the functions? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Malkey Posted October 8, 2011 Share Posted October 8, 2011 Here is something. #cs Array Layout: $Array[0] = "one" $Array[1]: $Array2[0] = "Two" $Array2[1]: $Array3[0] = "Three" $Array3[1] = "Last element" #ce #include <Array.au3> $Array = Array1() ; Original copy of $Array $aTemp1 = $Array[1] $aTemp2 = $aTemp1[1] $aTemp2[1] = "Changed element" ; Last element changed _ArrayDisplay($aTemp2) Func Array1() Local $Array[2] = ["one", Array2()] Return $Array EndFunc ;==>Array1 Func Array2() Local $Array[2] = ["two", Array3()] Return $Array EndFunc ;==>Array2 Func Array3() Local $Array[2] = ["Three", "Last element"] Return $Array EndFunc ;==>Array3 Link to comment Share on other sites More sharing options...
Shaggi Posted October 9, 2011 Author Share Posted October 9, 2011 Lovely, now the quiz winner is cleared up, I might have a pop at solving it myself. What do you regard as the "original array"? The global one, or one of those in the functions? Good. The global $Array. Here is something. #cs Array Layout: $Array[0] = "one" $Array[1]: $Array2[0] = "Two" $Array2[1]: $Array3[0] = "Three" $Array3[1] = "Last element" #ce #include <Array.au3> $Array = Array1() ; Original copy of $Array $aTemp1 = $Array[1] $aTemp2 = $aTemp1[1] $aTemp2[1] = "Changed element" ; Last element changed _ArrayDisplay($aTemp2) Func Array1() Local $Array[2] = ["one", Array2()] Return $Array EndFunc ;==>Array1 Func Array2() Local $Array[2] = ["two", Array3()] Return $Array EndFunc ;==>Array2 Func Array3() Local $Array[2] = ["Three", "Last element"] Return $Array EndFunc ;==>Array3 Obviously on your way, but you are still making copies Modify only the original. Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG Link to comment Share on other sites More sharing options...
Mikeman27294 Posted October 9, 2011 Share Posted October 9, 2011 Hahaha and I am no genious, but I presume that using _ArrayAdd would be cheating (Mainy because it isnt nested). Link to comment Share on other sites More sharing options...
JohnOne Posted October 9, 2011 Share Posted October 9, 2011 (edited) #include <Array.au3> $Array = Array1() Array4($Array) $AE1 = $Array[1] _ArrayDisplay($AE1[1]) #cs Array Layout: $Array[0] = "one" $Array[1]: $Array2[0] = "Two" $Array2[1]: $Array3[0] = "Three" $Array3[1] = "Last element" #ce Func Array1() Local $Array[2] = ["one",Array2()] Return $Array EndFunc Func Array2() Local $Array[2] = ["two",Array3()] Return $Array EndFunc Func Array3() Local $Array[2] = ["Three","Last element"] Return $Array EndFunc Func Array4(ByRef $a_Array) $a1 = $a_Array[1] $a2 = $a1[1] $a2[1] = "Modified" $a1[1] = $a2 $a_Array[1] = $a1 EndFunc Edited October 9, 2011 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Shaggi Posted October 9, 2011 Author Share Posted October 9, 2011 (edited) Hahaha and I am no genious, but I presume that using _ArrayAdd would be cheating (Mainy because it isnt nested). Wouldn't work any way #include <Array.au3> $Array = Array1() Array4($Array) $AE1 = $Array[1] _ArrayDisplay($AE1[1]) #cs Array Layout: $Array[0] = "one" $Array[1]: $Array2[0] = "Two" $Array2[1]: $Array3[0] = "Three" $Array3[1] = "Last element" #ce Func Array1() Local $Array[2] = ["one",Array2()] Return $Array EndFunc Func Array2() Local $Array[2] = ["two",Array3()] Return $Array EndFunc Func Array3() Local $Array[2] = ["Three","Last element"] Return $Array EndFunc Func Array4(ByRef $a_Array) $a1 = $a_Array[1] $a2 = $a1[1] $a2[1] = "Modified" $a1[1] = $a2 $a_Array[1] = $a1 EndFunc Task obviously solved, but this is still making use of copies - it is entirely possible without temporary objects Edited October 9, 2011 by Shaggi Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG Link to comment Share on other sites More sharing options...
JohnOne Posted October 9, 2011 Share Posted October 9, 2011 Ah but I never copied the original array, just an element of it. I have no idea though how to do drill into it without any copies. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Ramzes Posted October 9, 2011 Share Posted October 9, 2011 What do you think about DllStructCreate and DllStructSetData? Sorry for my bad English but nobody is perfect. [font=arial, helvetica, sans-serif]Ramzes[/font] Link to comment Share on other sites More sharing options...
UEZ Posted October 9, 2011 Share Posted October 9, 2011 (edited) #include <Array.au3> $Array = Array1() #cs Array Layout: $Array[0] = "one" $Array[1]: $Array2[0] = "Two" $Array2[1]: $Array3[0] = "Three" $Array3[1] = "Last element" #ce $a2 = $Array[1] $a3 = $a2[1] $a3[1] = "Modified" _ArrayDisplay($a3) Func Array1() Local $Array[2] = ["one", Array2()] Return $Array EndFunc Func Array2() Local $Array[2] = ["two", Array3()] Return $Array EndFunc Func Array3() Local $Array[2] = ["Three", "Last element"] Return $Array EndFunc Ok, same solution as Malkey has posted! Br, UEZ Edited October 9, 2011 by UEZ 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Ascend4nt Posted October 9, 2011 Share Posted October 9, 2011 (edited) Hmm, interesting problem. I would say a simple recursive function on a 'ByRef' array could do it. expandcollapse popup$Array = Array1() #cs Array Layout: $Array[0] = "one" $Array[1]: $Array2[0] = "Two" $Array2[1]: $Array3[0] = "Three" $Array3[1] = "Last element" #ce Func Array1() Local $Array[2] = ["one",Array2()] Return $Array EndFunc Func Array2() Local $Array[2] = ["two",Array3()] Return $Array EndFunc Func Array3() Local $Array[2] = ["Three","Last element"] Return $Array EndFunc Func _ArrayGetNestedArrayItem(ByRef $aArray,$iRec=0) If $iRec=0 Then Return $aArray[1] Return _ArrayGetNestedArrayItem($aArray[1],$iRec-1) EndFunc Func _ArraySetNestedArrayItem(ByRef $aArray,$vVal,$iNestLevel=0) If $iNestLevel Then _ArraySetNestedArrayItem($aArray[1],$vVal,$iNestLevel-1) Return EndIf $aArray[1]=$vVal EndFunc ConsoleWrite(_ArrayGetNestedArrayItem($Array,2)&@CRLF) _ArraySetNestedArrayItem($Array,"Changed Element",2) ConsoleWrite(_ArrayGetNestedArrayItem($Array,2)&@CRLF) *edit: forgot to add 'ByRef' in 'Get' call (though that wasn't part of this exercise) Edited October 9, 2011 by Ascend4nt My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted October 9, 2011 Share Posted October 9, 2011 He already posted the answer on the tracker, #2029 .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Ascend4nt Posted October 9, 2011 Share Posted October 9, 2011 He already posted the answer on the tracker, #2029 Interesting, I wouldn't have thought to look there. It appears to be the same solution, so I guess I passed Hmm, this is my 1000th post. There should be cake. My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted October 9, 2011 Share Posted October 9, 2011 Interesting, I wouldn't have thought to look there. It appears to be the same solution, so I guess I passed Hmm, this is my 1000th post. There should be cake.Congratulations!! You could take a screenshot and hang it on your wall .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Shaggi Posted October 9, 2011 Author Share Posted October 9, 2011 Hmm, interesting problem. I would say a simple recursive function on a 'ByRef' array could do it. expandcollapse popup$Array = Array1() #cs Array Layout: $Array[0] = "one" $Array[1]: $Array2[0] = "Two" $Array2[1]: $Array3[0] = "Three" $Array3[1] = "Last element" #ce Func Array1() Local $Array[2] = ["one",Array2()] Return $Array EndFunc Func Array2() Local $Array[2] = ["two",Array3()] Return $Array EndFunc Func Array3() Local $Array[2] = ["Three","Last element"] Return $Array EndFunc Func _ArrayGetNestedArrayItem(ByRef $aArray,$iRec=0) If $iRec=0 Then Return $aArray[1] Return _ArrayGetNestedArrayItem($aArray[1],$iRec-1) EndFunc Func _ArraySetNestedArrayItem(ByRef $aArray,$vVal,$iNestLevel=0) If $iNestLevel Then _ArraySetNestedArrayItem($aArray[1],$vVal,$iNestLevel-1) Return EndIf $aArray[1]=$vVal EndFunc ConsoleWrite(_ArrayGetNestedArrayItem($Array,2)&@CRLF) _ArraySetNestedArrayItem($Array,"Changed Element",2) ConsoleWrite(_ArrayGetNestedArrayItem($Array,2)&@CRLF) *edit: forgot to add 'ByRef' in 'Get' call (though that wasn't part of this exercise) Correct answer! Congrats. This was my solution: ShowOne($Array) ShowOne($Array[1]) ShowNest($Array[1],1) ChangeNest($Array[1]) ShowNest($Array[1],1) Func ChangeNest(ByRef $Array, $Val = -1) If $Val == -1 Then ChangeNest($Array[1],"Changed!") Else $Array[1] = $Val EndIf EndFunc Func ShowOne($Array) _ArrayDisplay($Array) EndFunc Func ShowNest($Array,$Index) _ArrayDisplay($Array[$Index]) EndFunc He already posted the answer on the tracker, #2029 Damn me... Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG 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