Widget Array from Struct Map Variable

Hello, I am creating this widget that has a scroll box of many different items that can be “purchased”. I have created a struct map variable with all the different items:

I then created a sub widget that would hold that values I would like to be shown on the page:

351041-350973-subwidget.png

Now the question is, how would I go about populating the values with the values in each struct in the map variable and only creating enough sub widget for the set amount of struct in the variable?

~Thanks

Ok, so after talking with some people I have created some new code so that the subwidgets are created in the scroll box for each struct map key. However, when I play the game, nothing pops up, and when I close it, I get multiple errors saying that the inputted text in the event returns null for each item property (ie: Price, quantity, etc). Here is the code that is run off event construct, and the event that is called from it.

The problem with doing it by value, is that you add every value into the scroll box, however, I have a sub widget that that I want the values to be put into for each key, then put the sub widget in the scroll box after the values are put in.

Like this:

Maps aren’t ordered - not sure if that’s important to you.

I’d skip the Find, there’s no need for this (unless there is further down the line). All the data is in the struct anyway - I’d use Values instead, as in the original pic. Simpler & cleaner.


It’s not working because the widgets get orphaned immediately after construction:

Unrelated but I’ll just add that one can expose data pins so each object can call its own event internally on Construct.

Use Keys then. I don’t know all factors necessary to make it work the way you need it to - going by the info provided. In short, remember to add a child. Setting Owner is not enough.

Looks like it should work, things to double check:

  • ensure the text fields are not bound to variables / functions
  • ensure the Map has the data you think it does at the very moment of creating a widget (print it)

Ok, so I have gone ahead and have done the add child after constructing the widget, then I call the UpdateEntries event, however the values are not being populated properly. Also, here’s and picture of the sub widget where the values of each key in the map variable go.

And here is the structure of the struct map variable.

351137-variable.png

Another thing I’ve noticed is that you’re constructing objects rather than creating widgets explicitly:

Not sure if that’s important but I generally use Construct for native widgets and Create for user widgets. Might be a force of habit. Can’t tell if there are any tangible downsides.

The shape of the pin indicates whether data was passed as a copy (round) or by reference (diamond). Above, Find makes a copy of the struct and from now on we operate on the copy that never makes it back into the original Map.

Updating with Add would be the best choice here, as in the answer you’ve accepted.

Good luck with the rest.

Ok, I got it to work. So now the next question is, when I add one to the purchase quantity as shown, and then print the value in update widget after applying the value to the sub widget, the value doesn’t change.

After looking through some previous concerns, I have found the solution to my last response. What I was doing was setting the members in the product struct however, there are multiple members. So instead, I set the members with the add function for the map variable so that it would override the values with the ones I wanted to set.