Using a Function to Format your Dialogue
This was touched on in the first tutorial, but I’m going to take it a bit further in this one. The example file included shows off a lot more of the BBCode tags you can use with the Text object, so the function does look a tad unwieldy! You might not need all of the tags, but it's good to show them working!
Essentially, each action runs through the current line of dialogue and replaces a specific value in the text to the correct BBCode tag. This is then set as the return value for the function which is then used to display the correctly formatted text.
You’ll need to make sure that you’re using the correct tags for your specific situation though. Spritefont objects and Text objects use different BBCode tags for formatting, and you can see which ones are usable on the manual pages for each object.
You may have noticed that at the end of this rather large function, there is a replace expression which has nothing to do with BBCode. You can also use this function to replace sections of the text with a variable! In this example, there’s a global variable called PlayerName, which can then be plugged into the replace expression so that whenever the term ‘PlayerName’ is used in the JSON file, it’s replaced by the value stored in the variable!
So, your text looks good, but what else can we do with dialogue? Well, how about calling functions?