Adding Buttons only if database Text exists?

Hey there,

For the first time In while Im stumped. Ive been feeling really good with my unreal knowledge and made some real headway into a second game. Really enjoying it.

This time round Im trying to make random events.

The random events work. But different Random events may have multiple choices or choices that come later.

So this is the example:
1.If your brain power is 0.
Then the pop up arrives and only gives you the option to close the pop up while giving you infomatiom.

  1. If your brain power is 3 then the pop up arrives with close but also has another button for say “Shoot brain laser”

So I guess the question is how do I only show buttons for when certain options are avaliable.

My only guess is to make say as many buttons with texts tied to the datasheet that has all the responses etc on.

and then make them invisible and only make them visible if text exists for that response.

It just seems like such a long work around for what is basically

If text exists. add button with datasheet response.

Anyone got any ideas?

Thankyeee

Ive had a dig about. Would this be the best course of action or am I going down a rabbit hole with this?

Ok so I swapped my datasheet for an array Text and added that to a for each loop.

Creating a object button in blueprint and it gives me the buttons required.

Now I just need to apply texts over it and somehow use the button that gets created

If you need a button + text, make a user widget and create those. This way you can also add a custom event dispatcher, making the button send some unique, randomly generated data it was fed when created.

Hey, Ive rewritten this out a bunch :laughing: I cant work out how to explain it.

Thats exactly what I need. Ive built Several iterations but Im getting stuck at the same point regardless of approach.

I feel like Im circling the answer, I spent last night and a bit this morning trying to figure it out and I think it comes down to:

How do I create multiple dynamic buttons without endlessly creating more widgets?

I need to create a button and text for every input for an array.

So im thinking.

Construct the button/text user widget.

Then inside of the user widget, use construct object of class to create buttons based on an array. and then place the text inside of the created buttons. hmm

But then I guess how do you bind an event to buttons that arent created yet.

Ah god dam it. im circling

edit:

I need sometype of get all buttons node into an array and then apply the text into it.
And then someway to apply individual outcomes based on the current datarow its on.

You bind it dynamically when they get created.

I need to create a button and text for every input for an array.

  • widget with a Button + Text + bind the string which is exposed variable, onClick event and an Event Dispatcher:

  • we add a bunch of our custom buttons (here, to a vertical box) that do stuff based on what we feed them:


I need sometype of get all buttons node into an array and then apply the text into it.

If your buttons are created upfront and you wish to update them:

And then you can query their container:

Ahhh thats genius!

Ive been studying it for like 2 hours lol, That works beautifully. I understand a solid 90% of it which is good for me :laughing:

The 2 parts I dont fully understand are the string variable and how to limit buttons depending on an array.

  1. The string variable “Do this” I feel is basically a cargo ship. Just a way to pass unique infomation for unique inputs and outcomes.

  2. If you make it a custom event to dynamically adjust how many buttons there are, it works beautifully…Once. After that your just adding and adding widgets as your just looping the create event so thats not an option.

So youd need to create a dynamic amount of buttons after the construct maybe.
Maybe thats done inside of events? Or maybe this is where youd use create object (Buttons) and add them depending on the array input?

Unfortunatly Im out of time this morning :(. Im gunna be pondering this at work.

Thank you for all your help! This is an absolutly huge step forward today :trophy:

edit: Im trying to add an image but Im getting a discourse:Invalidaccess error :frowning:

Yup - just an example of how to assign data to the widget and then have it dispatched upon request.

If you make it a custom event to dynamically adjust how many buttons there are, it works beautifully…Once. After that your just adding and adding widgets as your just looping the create event so thats not an option.

Not sure I follow.

  • we have an array of data
  • we loop through that array and create a bunch of user widgets, each holding a piece of data from that array
  • then whut?

Adding Buttons only if database Text exists?

Not entirely sure what the end goal is. Let’s say you have a Data Table and only certain entries have text; we need no widgets if there’s no text, so:

Woo finally got a picture to work(Think the file size was to large), Im much more visual and struggle to explain things. Hopefully this makes more sense.

Im trying to limit the amount of buttons made depending on how many answers are in the array. The array size is dependent on the Row your on in the data sheet.

So Row one has only 1 answer in the array and needs 1 button with unique text
But Row two has 2 answers in the array and needs 2 buttons with unique text

I was thinking another way is to destroy all children(buttons) once the box is closed and thatll avoid the buttons stacking if I used a custom event. but I think I read somewhere you cant fully destroy/delete/vaporize widgets once they are made, theres always trace left or something. I need to refind the reference about it but it equally could be bs :laughing:

Now I understand more about how to upload images, I can show anything else youd need to see.

You can clear widget containers before you repopulate them, it’s common practice. Providing you’re not referencing the widgets anywhere else, they will be removed from memory by the Garbage Collection system. It may take a minute to do so as objects are packed into clusters for removal to make it more efficient.

The loop nodes take integers variable for the range, modify the variable and re-run the loop.

If you have some pre-made buttons present, you can update the existing ones and only then add extras. But I wouldn’t bother optimising this process unless you’re making a lot of them often. Then you could make a pseudo-pooling system.


Also note that doing what you’re doing during construct may not be the best idea - construct is often called more than once. Consider using Event On Initialise instead → especially when you do bindings:


If you do this:

There is no place to take the data from for the widgets’ exposed var.


I think I read somewhere you cant fully destroy/delete/vaporize widgets once they are made, theres always trace left or something. I need to refind the reference about it but it equally could be bs

Widgets used to leak memory in certain scenarios before v4.22 or thereabout, true. This is no longer the case but it’s not entirely impossible that bugs remain, ofc.

Thats crazy interesting! Is garbage collection Something youd need to force? Like using the garbage collection node? Or is it automatic?

Is there a way to check if the garbage check was complete?
Kind of like a get all widgets of type or something and print the amount, And youd be able to see if drop to 0 or something?

Interesting also. Ill need to look into when each one is viable, thatll make some good reading at work.

Ohh I see.
I thought the array index was telling the select how many were in the array and then the array element was filling those.
But having disconnected it, The system still works.

Ok Yeah Ive fundementally Smoothed my brain over. I need to really just stare at this for a bit. I dont know where Ive gotten myself lost or why I cant understand it.

I need the loop to be controlled by the amount in the array.

So something like this?

Because the select starts at 0, and the array starts at 1, Ive just N/A the first option and started from 1, seems a janky workaround but it works in terms of how many buttons are created based on the array length in the data sheet.
But then Im circling again in how to add the text from the data sheet as well which leads back to my original incorrect system.

I apologise, I have misunderstood and boxed myself in mentally. I feel very close but I Need to go through each individual piece and really understand what each part is doing, I have to go to work and Im rushing trying to understand it before I go and leading myself astray I feel.

Thank you again for all of your help and time! It makes a huge difference and I am feeling incredibly close to understanding the knowledge.

It’s automatic but you can also force it. ForEach was fine here:

You asked about how to control a loop:

image

It can be adjusted after creation, run it again with new values.


I admit that I do not understand what the end goal is. Perhaps what you wanted was exposing Out Row Answers:

Feed this widget an array when it’s created and it will, in turn, create an appropriate number of custom buttons. In this case you must run it during Construct as the variables are not Initialised when the widget initialises. Which is as odd as it sounds.

OMG THATS IT. thats the one! ah thank you! I think Ive got it.

1.The maths random event runs.

2.It tells the random event which row its on, sets up the image and the text based on the random encounter and then sends the outputs to build buttons.

The row in the datatable has infomation for how responses that random event might have (How many buttons and text itll need per random incounter)

  1. the build buttons event, then creates the Required buttons based on the output array and adds the text. and builds the exit bind with the default hide event ready for another and removes the children ready for garbage collection and the next encounter. etc

  1. Well…Now I guess I gotta work out how to attach unique instances depending on the output.

I equally could change the text to string in the structure and assumably itd work exactly the same or anywhere along the line I guess If I need more adjustability.

I hope I have understood everything correctly, My haste and eagerness to learn fried my brain But I have a day off today due to half term and manage to slow down and really study your words.

I can thank you enough! :trophy: :trophy: If you have any more infomation or I have made a mistake In my final noding, I would love to continue refining it. Thank you again!