[solved]Libgdx json loading a string containing variables

So, I’ve been playing around on an rpg project and finally got conversational elements working, but I can’t figure out how one would go about loading the strings in such a way that the text could read like

“Welcome hero name…” and it would parse out to whatever the character name, I know its possible because java games do this regularly… I’m using json.

As it stands the player moves to the character, who sets a flag that starts the conversation and accepts input, but so far can only fgure out static text.

thanks

Here is a simple way.


String heroName = "bmanmcfly";
String message = "Welcome {heroName}...";
message = message.replaceAll( "{heroName}", heroName );

Oh, so,


{
  "conversations": [{
    "id": "Intro",
    "text": "Hi this is {heroname} sample text"
  }
  ],
  "availableChoices": [{
    "sourceId": "Intro",
    "command": "EXIT",
    "choicePhrase": "Goodbye"
  }
  ],
  "currentConversation": "Intro"
}

is the json code sample I’m using to load conversation files and then where I parse the text replace all with appropriate variables…

OMG, thanks, I was looking for days, the bonus part is, because the variables are all temporarily held in a loader class, I can do replace alls in a generic way that can cover all cases… thanks