bbaanngg
Member-
Content Count
6 -
Joined
-
Last visited
-
Medals
Community Reputation
0 NeutralAbout bbaanngg
-
Rank
Rookie
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
-
Circular Reference in HashMap
bbaanngg replied to bbaanngg's topic in ARMA 3 - MISSION EDITING & SCRIPTING
I agree. Only the keys of a hashmap need to be hashable. From https://community.bistudio.com/wiki/HashMap: I generalized the problem for the sake of this post. In the actual implementation the maps are not empty, so that doesn't matter. My original problem consisted of storing an array of maps and a subset of that array under separate keys in the same parent hashmap. The parent map is a "point cloud" object created using createHashMapObject. The two arrays are populated with "point" object hashmaps. The first array describes all points of the point cloud, and the second array is the subset of the first array that creates the convex hull of the point cloud. See: p1 = createHashMapObject [...]; p2 = createHashMapObject [...]; ... PointCloud = createHashMapObject [...]; PointCloud set ["points", [p1, p2, ...]]; PointCloud set ["convex_hull", [p1, ...]]; The array of "points" will never change in my use case, so I can just store the indexes of the desired points in the "convex_hull" array to avoid the "circular reference". However, your solution sounded good for a scenario where the first array is subject to change, so I did some testing. I figured the problem with converting to an array would be keeping both values referencing the same map, and that seems to be the case: (note that specifying non-split arrays with toArray is required for createHashMapFromArray to work when using nested hashmaps.) _m = createHashMapFromArray [["a", 1]]; p = createHashMapFromArray [["m1", _m], ["m2", _m]]; [missionNamespace, "OnSaveGame", { p = p toArray false; }] call BIS_fnc_addScriptedEventHandler; addMissionEventHandler ["Loaded", { params ["_saveType"]; p = createHashMapFromArray p; }]; Placing the above code in the init.sqf and running the mission looks promising at first. The save event handler properly avoids the circular reference error, and loading the save also restores the hashmap, but unfortunately, if you run the following code after loading the save: p get "m1" set ["a", 2]; p get "m2" get "a"; It does not return 2. Which shows that "m1" and "m2" no longer reference the same map. However, if you run the following code and then save the game: a = call { _m = createHashMapFromArray [["a", 1]]; _p = createHashMapFromArray [["m1", _m], ["m2", _m]]; _p toArray false; }; Then test the reference using the following code: p = createHashMapFromArray a; p get "m1" set ["a", 2]; p get "m2" get "a"; If you load the save and then test the reference, "m1" and "m2" no longer reference the same map. However, if you save the game and test the reference without loading the save, the reference is retained. Will do, thanks for your help. -
m = createHashMap; map = createHashMap; map set ["a", m]; map set ["b", m]; If you run this code in the debug console and then attempt to save the mission the following message will be logged to the rpt file: Circular reference found in HashMap, this will cause a memory leak! ➥ Context: Hash Key: "b" <- Serialize Game Variable: map However if you run the following code: a = []; map = createHashMap; map set ["a", a]; map set ["b", a]; No such error is logged. Can anyone explain this behavior? Specifically, why can you store two references to the same array but not to the same hashmap? Thanks.
-
Creating an array from a stringtable
bbaanngg replied to bbaanngg's topic in ARMA 3 - MISSION EDITING & SCRIPTING
I was hoping there would be a way to do it within arma but figured there wouldn't be. Thanks for this though, will save a lot of time! -
bbaanngg started following Spawning Units in X amount of Groups and Creating an array from a stringtable
-
Creating an array from a stringtable
bbaanngg posted a topic in ARMA 3 - MISSION EDITING & SCRIPTING
I'm using a stringtable.xml to store text dialogue for my mission. Is there any way to create an array of all keys within a container? For instance, if I have something like this: <Package name="Dialogue"> <Container name="Greeting"> <Key ID="STR_Greeting1"> <Original>Hello.</Original> </Key> <Key ID="STR_Greeting2"> <Original>Hi.</Original> </Key> </Container> I want to make a function that will create an array of all the keys inside the "Greeting" container in an sqf file. Something like this: _greetigns = ["STR_Greeting1", "STR_Greeting2"]; so that I can localize them and use them in order. Is there any way to do this? -
Spawning Units in X amount of Groups
bbaanngg replied to bbaanngg's topic in ARMA 3 - MISSION EDITING & SCRIPTING
Thanks for the help. I actually didn't know you could create the group and the unit in the same line like that. I ended up using this: private _unitClasses = ["class1", "class2", "classN"]; { private _u = createGroup OPFOR createUnit [selectRandom _unitClasses, markerPos _x, [], 25, "NONE"]; } forEach _Markers; It works perfectly, thanks again! -
Spawning Units in X amount of Groups
bbaanngg posted a topic in ARMA 3 - MISSION EDITING & SCRIPTING
In a project I have been working on I use this code to spawn empty groups based on how many markers are in a trigger. { missionNamespace setVariable [format["grp%1",_x], createGroup east]; } forEach _Markers; So how would I go about spawning 1 opfor unit in each group until all groups have 1 unit in them? Or is there a better way of doing this in general?