Replace string in Datatable with variable created in widget?

You can’t write to a Data Table in BPs. You’d generally use a save game object to store persistent data.

  • load the data from a data table into a struct in the character bluerprint
  • you’re free to modify that struct
  • when you’re ready to save, push that struct into a save game object
  • save the object to disk

when loading:

  • load the save game object from disk
  • read the struct and set it as player’s data

Hello,

Currently, I am working to set a players name which eventually interacts with a script that I have set through a data table.

I am rather new to Unreal, but I do understand many forms of coding, so the idea itself would work something along these lines.

Widget opens > player inputs text through textbox > textbox saves data > data is sent to a variable > that variable replaces the specific name in the data table

The only issue I have at the moment is I am not quite sure how unreal handles something like this, what constitutes a variable outside of blueprints and the like.

My structure would currenty look like this

Datatable:

Row / Character / SpokenWord

1 PlayerName “blah blah”

Finally, my end goal is to replace the playername string in my character category with my PlayerName variable which I have made public in my specified blueprint.

Is this something that I can pull off, or is there another way I would need to go about it?

Thank you in advance for any assistance you can offer.

Widget opens > player inputs text
through textbox > textbox saves data >
data is sent to a variable > that
variable replaces the specific name in
the data table

If it’s just for interaction, why not have the script read the player’s current name? You can handle text input like so:

This data persists until you destroy the widget, load a new map, you quit / your game crashes.

That’s sort of what im hoping to do. The issue is the script itself has all dialogue spoken by the player as playername, and im trying to set playername to whatever is input by the textbox, but im not quite sure how to do that.

For something straightforward, the dialogue handler (I’m assuming you have a separate object / manager doing this?) could query the player for their name:

Even easier if it’s the player outputting dialogue lines to the screen.

This might be exactly what im looking for, while I mess around with it, heres a few more information if you want to clarify and see if it’s still valid

since im bringing the information in via CSV, charname has multiple instances for multiple speakers and such, so my goal is specifically changing any row with playername to my PlayerName variable.

I really appreciate the help so far, im going to look at what you’ve already shown me and see what it does in the meantime!

since im bringing the information in
via CSV, charname has multiple
instances for multiple speakers and
such, so my goal is specifically
changing any row with playername to my
PlayerName variable.

Ah, it’s much clearer now! You can replace substrings like so:

Can be done in a loop for a bulk-edit style replacement. So once you’ve got the Data Table structs in an array, you can modify them and use ready-to-go lines with correct names.


Somehow I feel this is redundant, and simply reading a string and parsing it (format text) is more efficient and more flexible. Although I guess you could do it on a per-dialog basis rather than replace player name in all strings. What if the player renames themselves again?

I’ve turned it into an answer, but do follow up if structs give you headaches. There’s some gotchas when working with them.

This actually did exactly what I wanted, bless you very much

As for you footnote, ya I can see that. For the moment however, I am going to keep this going as I don’t think that will happen on the same save file.

Appreciate all the help!

Will do, at the moment my dialogue system sort of works like you would see in a visual novel. So unless I make some changes to how I bring in the script data, structures are probably my best bet.

Thanks so much for the help!

Hate to bring this back up since yesterday, but building upon what you said, what would you suggest about the string/datatable reading? As of right now, other than the datatable, I am not quite sure how else to import a script, especially one that’s editable. Fiddling around with your answer more made me realize that I might get some bad issues when the player’s name is called in the general dialogue columns.

But I believe it’d be easier to parse a fetched string from the DT and display it. This way the only thing you need to do is to replace a placeholder player name.

Read the data table structs and add them to an array or a Map. This way you end up with something you can modify (and even save).