Adding a new Entry in a Struct holding a TArray as Member value doesn’t update it’s entries - arrays

I am currently working on a Character Customization System where a HUDLayout dynamically create Widgets based on a set of Skins available for the Character Selected. A Skin is represented as a Struct called MaterialInstanceContainer and holds a TArray. Player can mix and match their selection according to the Body Parts they select. In order to achieve the final result, I want to create a TMap<string, MaterialInstanceContainer> so that I can map each BodyParts available for selection with the individual material instance targeting the same BodyPart.
ISSUE: My issue is as follow, when I try to foreach over my collection of Material Instances inside my Container, I do a string comparison and if the output is valid, I can then break my struct to access the Material Instance Array and ADD to it however, at the very end of the process, the length of the array inside Material Container is still at zero.
How can I add a new entry in the array that my Material Container Struct hold?
Thanks!
enter image description here

The issue here is actually pretty straight forward: in Blueprints when you 'Find' a member of Map you are not getting it by-reference, instead you get the copy.
This is exactly what happens at the end of your nested loop: You get a copy, you add item to it, and when another iteration kicks-in the copy gets terminated.
And here on my side it returns exactly the same result as expected:
The fix for that would be easy:
After editing a Copy, you can overwrite the Map member by its copy (via 'Add' node).
But in your case it will be more tricky. You cannot just plug the same BreakStruct/Array node that you just used because it would call whole Find sequence again which creates another copy. Look
If you are confused. This code actually looks like this for Unreal's point of view.
So you have to store the the Struct in local variable first, then perform any operations on it and after everything is done - overwrite the Map member by its locally stored copy. And the result is
Map member gets overwritten every time and everything is as it should be.
Well, almost... For some reason your code is stored in Macro. I think you have to change it to a Function to be able to create local struct variable. But it shouldn't be a problem in this specific case because in your code there is no logic that needs to be done in macro.
Hope, it helps

Related

How to delete a piece of data from an array inside a Nested Collection?

I want to delete an item from an array that is inside a collection that is inside another collection (A nested collection) I have all the data that I need to achieve this, however I do not know how to write I have a slightly idea of how to (I'll be testing stuff on my own, but will leave the question here as well)
I'm using Material UI DataGrid to render my tables and to delete/edit them. I have a piece of information that is saved on my Local Storage in case I required it:
this is how my table looks:
When I select an ITEM and delete it is holding the ID of the item in the data:[Array]
those IDs are the IDs they hold in the data[array] -> :
finally I need to access this document, well I have the following
db.collection("usuarios").doc(user.uid).collection("pedidos").doc(id)
which brings the following:
which means I'm bringing the correct document, however I have no idea how to "update" or delete the array called data[], any ideas? What I want to achieve is that when I press the delete button it will update the array based on the Item selected so if it was Item ID: L-2627 then go through the array inside that collection, get the array called data and delete the item stored in the array.
Read the document into memory.
Modify the array by finding the item and removing it, again from memory.
Write the modified contents back to the document.
There is no shortcut or single operation for doing any this. The fact that the document is in a subcollection doesn't change anything. It's just how you have to modify arrays when you don't know the entire contents of the array item ahead of time.

ngAnimate to detect changes from $http-call with interval

I have an array with a few items in it. Every x seconds, I receive a new array with the latest data. I check if the data has changed, and if it has, I replace the old one with the new one:
if (currentList != responseFromHttpCall) {
currentList = responseFromHttpCall;
}
This messes up the classes provided by ng-animate, as it acts like I replaced all of the items -- well, I do actually, but I don't know how to not.
These changes can occur in the list:
There's one (or more) new item(s) in the list - not necessaryly at the end of the list though.
One (or more) items in the list might be gone (deleted).
One (or more) items might be changed.
Two (or more) items might have been swapped.
Can anyone help me in getting ng-animate to understand what classes to show? I made a small "illustation" of my problem, found here: http://plnkr.co/edit/TS401ra58dgJS18ydsG1?p=preview
Thanks a lot!
To achieve what you want, you will need to modify existing list on controller (vm.list) on every action. I have one solution that may work for your particular example.
you would need to compare 2 lists (loop through first) similar to:
vm.list.forEach((val, index)=>{
// some code to check against array that's coming from ajax call
});
in case of adding you would need to loop against other list (in your case newList):
newList.forEach((val, index)=>{
// some code to check array on controller
});
I'm not saying this is the best solution but it works and will work in your case. Keep in mind - to properly test you will need to click reset after each action since you are looking at same global original list which will persist same data throughout the app cycle since we don't change it - if you want to change it just add before end of each function:
original = angular.copy(vm.list);
You could also make this more generic and put everything on one function, but for example, here's plnkr:
http://plnkr.co/edit/sr5CHji6DbiiknlgFdNm?p=preview
Hope it helps.

Test for corrupted list

Suppose I receive a list in a volatile environment, where the tail element is only partially filled with accessible items; further, passing on/deleting/dropping the element is a perfectly adequate solution.
So,
next->A // is unaccessible
next->B // is accessible
if (next->A) // evaluates to true
is there a method to test and pass/delete this list element?
C does not provide a built-in way of testing if a memory location is accessible or not. You cannot check if next->A is available for the same reason that you cannot check if a pointer is "dangling".
A fix to this is to add a level of indirection: make a list of "envelope" objects which are always available. Each envelope holds a pointer to the actual object, along with a flag indicating object's accessibility. This way the provider of the list would be able to manipulate the flag independently of the data object itself, without disturbing the content of the list:

ActionScript 2 - Get MovieClips' initial position and save it for each mc for later target position

I am working on an animation in AS2 which requires that all text MovieClips (instance names starting with "txt_") will be manually placed initially on stage and I need to store their own initial placed positions (x,y) so they will be retrievable later when I want to animate them to these same final coordinates regardless of where they move around in the meantime.
So the following steps needed:
All these text movieclips are placed on stage manually from library (not dynamically) matching their expected target keyframe end position (x,y) to get desired final screen layout.
Then a frame script loops through all these MovieClip instances on stage before rendering them on stage and stores their initial (also future target) (mc.targetPosX or mc.targetPosY) positions.
Then frame script also moves all of these MovieClip instances before rendering them on stage and moves/offsets them elsewhere on stage (eg. mc._x +=25px;) and hides them (eg. mc._alpha =0;)
Finally by using a tween like Greensock I want to use their stored target end position to animate each of them to their stored final target position.
(eg. TweenLite.to(mc, 1,{_alpha:100, _x:mc.targetPosX, ease:Quad.easeOut});)
I was able to create a loop to get "txt_" movieclips but then I don't know how to save their target positions with their instance and use them outside the loop afterwards.
Thank you in advance,
Attila
I don't know what problems do you have trying store some variables inside instances, but here my suggestions about proccess you described.
First of all we have loop which do all thing you described at question.
To do so we must have some list of you mc's or pattern to make this list dynamically. From you question i suppose that you use this kind of loop.
for(var i=0, txtCount=10; i<txtCount; i++){
textMc = this['txt_'+i];
//do stuff
...
}
From here on your points.
You already did it.
Use loop described above to store current object properties inside his instance
textMc.storedX=textMc._x;
textMc.storedY=textMc._y;
Here is same loop place object wherever you like
textMc._x+=25;
textMc._alpha=0;
Finally right after that in the same loop use greensock.
TweenLite.to(textMc, 1,{_alpha:100, _x:mc.storedX, ease:Quad.easeOut});
That's it.

How to initialize a Ref<?> field in objectify to a dummy value

I have a collection(arraylist) of Ref `s ,the objectify documentation says that I need to initialize collections for them to be persisted and hence modified in the future.....
Now , Ref points to an object but when I launch my app for the first time I dont have any objects in the data store...so whats the best way for me to initialize a dummy value......
Is my assumption that a Ref<> needs to point to a real object in the data store?
Two things:
You should just initialize an empty collection. You don't need to add anything to it. eg, field = new ArrayList<Ref<Thing>>();
It's actually not even required that you initialize the collection. It's just a good idea for reasons that will become apparent if you use the system for a while.

Resources