Custom Escape Codes/Text Replacement

So, I’ve looked all over the internet for an answer to this question, maybe I’m not using the correct terminology, but I have not been able to find a solution.

Essentially, what I want to do is create custom escape code for text input through the editor (I’m planning to use ScriptableObjects for my dialogue system).

For example, if I wanted an NPC to say “Please bring me a Potion of Healing” I’d like to be able to type into the editor something like “Please bring me a \item[23]” and before the code displays the text, recognize the escape code for \item[23] and run code to search the item database for an item with an idNumber of ‘23’ and then return the itemName variable to replace in the code.

Back before I switch to Unity, I was using RPGMaker and was able to do something just like this when using the message system, so I’m just trying to find a way to replicate this for my game.

What you seek is called string parsing and/or regular expression (regex) parsing. Tons of links for that stuff in C#.

You need to use it twice for what you want:

  • analyzing the inputted string and chopping it into "Please bring me a " and then “\item[23]”

  • the second is just further parsing of the “interesting” bits you pull out such as “\item[23]” and looking it up in a repository of some kind

1 Like

Thank you, knowing the proper terminology should help me figure this out a lot easier!

1 Like