Jump to content

Recommended Posts

Posted (edited)

Im not sure if this is intended but normally Autoit variables are always passed as copies (except objects i think).

But below i observed an unconsistency when copying maps with nested maps inside.

Issue:

If you create a nested map1 and copy it to a new map2, changing a nested value in map2 will also change the nested value in map1

Dim $player[]
Dim $sub[]

$player.test1 = 1
$player.test2 = $sub
$player.test2.child1 = "org"
$player.test2.childext = $sub
$player.test2.childext.child1 = "org2"

$playerold = $player ; make a copy of the whole map

ConsoleWrite("player.test2.child1   : "& $player.test2.child1 & @CRLF); original nested value in $player

$playerold.test2.child1 = "changed" ; edit a nested value in $playerold

ConsoleWrite("player.test2.child1   : "& $player.test2.child1 & @CRLF) ; original nested value in $player changed

ConsoleWrite("---------------------" & @CRLF)

ConsoleWrite("player.test2.childext.child1   : "& $player.test2.childext.child1 & @CRLF); original level2 nested value in $player

$playerold.test2.childext.child1 = "changed2" ; edit a level2 nested value in $playerold

ConsoleWrite("player.test2.child1   : "& $player.test2.child1 & @CRLF); original level1 nested value in $player stayed the same

ConsoleWrite("player.test2.childext.child1   : "& $player.test2.childext.child1 & @CRLF); original level2 nested value in $player changed

 

Edited by qsek
Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite
Posted

That's how Map behaved. I used the past since it appears the implementation has a number of issues which precludes general public consumption.

Future will tell if they reappear in release versions but for now don't rely on beta Maps for serious apps.

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)

Posted (edited)

@qsek I just tried playing around with scripting dictionaries as they have similar uses, and they seem to behave the same way (although I could not get it to add a key/value pair to the nested, nested dictionary); updates to the nested dict updated the original.

#include <Array.au3>

Local $oPlayer = _DictionaryCreate()
Local $oSub = _DictionaryCreate()

$oPlayer.Add("test1", 1)
$oPlayer.Add("test2", $oSub)
$oPlayer("test2").Add("child1", "org")
$oPlayer("test2").Add("childext", $oSub)
;~ $oPlayer("test2").("childext").Add("child1", "org2")

Local $aItems = $oPlayer.Items
_ArrayDisplay($aItems,"oPlayer")

$aItems = $oPlayer.Item("test2").Items
_ArrayDisplay($aItems,"oPlayer.test2")


$oPlayer.Item("test2").Item("child1") = "childchanged"

$aItems = $oSub.Items
_ArrayDisplay($aItems,"oSub")


Func _DictionaryCreate()
    Local $oDict = ObjCreate("Scripting.Dictionary")
    If @error Then Return SetError(@error, 0, 0)
    Return $oDict
EndFunc

 

Edited by spudw2k
Posted

@spudw2k not really the same. As expected because it is an object that will execute Methods on its own and give the data to the parent.

That is also why you cannot add the 2nd level "child1" in

$oPlayer.Item("test2").Item("childext").Add("child1", "org2")

Because you already added it one level higher before to the same $oSub:

$oPlayer.Item("test2").Add("child1", "org")

Essentially what you are doing is

$oPlayer.Item("test2").{ $oSub.Add("child1", "org") }
$oPlayer.Item("test2").Item("childext").{ $oSub.Add("child1", "org") }

Also your $oSub on its own fills with items as you use it with $oPlayer as parent.

My Map $sub on the other hand will not fill with items. It is empty if you look at it after filling it with data with $player as parent. So internally it will create a new Map everytime you assign a submap like so.

$player.test2 = $sub

  and also when creating a second version on a deeper level in one parentmap. I think this is intended as you dont have a ObjCreate with Maps. However if the whole map is copied, it creates references of the individual submaps in the copied one, which i think is not intended.

 

 

Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite
Posted (edited)

After some trying i found a workaround:

Dim $player[]
Dim $sub[]

$player.test1 = 1
$player.test2 = $sub
$player.test2.child1 = "org"
$player.test2.childext = $sub
$player.test2.childext.child1 = "org2"

$player.a = $player     ; make a temporary copy of the whole map inside an unused key of the map to be copied.
                        ; This also forces the submaps to get their unique copies and all references to 'root' $player are cut.
$playerold = $player.a  ; So $playerold will recieve a independent copy of $player
MapRemove($player, "a") ; Temporary copy not needed any more

ConsoleWrite("player.test2.child1   : "& $player.test2.child1 & @CRLF); original nested value in $player

$playerold.test2.child1 = "changed" ; edit a nested value in $playerold

ConsoleWrite("player.test2.child1   : "& $player.test2.child1 & @CRLF) ; original nested value in $player changed

ConsoleWrite("---------------------" & @CRLF)

ConsoleWrite("player.test2.childext.child1   : "& $player.test2.childext.child1 & @CRLF); original level2 nested value in $player

$playerold.test2.childext.child1 = "changed2" ; edit a level2 nested value in $playerold

ConsoleWrite("player.test2.child1   : "& $player.test2.child1 & @CRLF); original level1 nested value in $player stayed the same

ConsoleWrite("player.test2.childext.child1   : "& $player.test2.childext.child1 & @CRLF); original level2 nested value in $player changed

 

Edited by qsek
Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite

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
×
×
  • Create New...