playMaker

Author Topic: Replace String's Wild Card Charas With...  (Read 2090 times)

westingtyler

  • Sr. Member
  • ****
  • Posts: 277
    • My Video Game Projects Web Site
Replace String's Wild Card Charas With...
« on: August 06, 2018, 04:49:38 PM »
I'd love an action like this:

input string
wild card (str) within that string
replace with (str)
store result (str)

So for instance, I could replace a specific character(s) in a string with new characters. Very handy for inserting a player's name into a pre-defined response, or for asking an NPC about an equipped object.

input string: "Hello, *. Do you have a donkey?
wild card: *
replace with: player name string (Biscuit)
store result: Hello, Biscuit. Do you have a donkey?

or
input string: No, I don't know anything about $equippeditem.
wild card: $equippeditem
replace with: player equipped item (Wire Cutters)
store result: No, I don't know anything about Wire Cutters.

This would be a super handy action. Thank you.


GonerGames

  • Junior Playmaker
  • **
  • Posts: 53
Re: Replace String's Wild Card Charas With...
« Reply #1 on: August 06, 2018, 08:40:46 PM »
Using Build string would work for that.
Set a global string variable as PlayerName and EquippedItem
Then use a Build String action:
Part One: Hello,
Part Two: PlayerName
Part Three: How are you today

etc.

Hope this helps.

westingtyler

  • Sr. Member
  • ****
  • Posts: 277
    • My Video Game Projects Web Site
Re: Replace String's Wild Card Charas With...
« Reply #2 on: August 07, 2018, 08:35:01 AM »
Hey, thanks. I actually need to be able to do this dynamically at runtime based on another string in the fsm being the thing inserted. I will be constantly retrieving the names of game objects and storing them in string variables, and I need to be able to insert those into OTHER arbitrary strings.

what I am essentially doing is that you can ask any character about any examined object, and it will check their personal array for a specifically written response, and if there isn't one, if will build one based on several changing factors like the current character you have, the equipped item, etc. And for certain characters, they will have a pre-written "I don't know" response that will insert the relevant dynamic pieces as requested.

The examples I gave were just little examples in a much more hefty system. Using the build string method I'd have to dynamically SPLIT pre-existing response dialogue lines, then build the string with the requested wild card. So I'd have to make a parser to dissect each line and create and store new strings at each wild card, and considering I might have even dozens of wild cards per line, there is a potentially unlimited number of NEW strings I'd have to parse and split up first. An action to simply check the string for a wild card then replace what is needed would be much simpler.

In other words, using the suggested method, I'd need hundreds and hundreds of global variables, which isn't as handy as being able to name a game object then retrieve its name later.

A bonus of the requested action is that I could create entirely new sentences based on stored phrases that could be inserted whenever needed....

which makes me also want to request an action to test if a string contains a specific wild card. For example, any dialogue line that contains & will replace that with "Howdy, partner!" since & could be the universal symbol for "cowboy intro." I'll suggest that after this.
« Last Edit: August 07, 2018, 08:42:33 AM by westingtyler »

GonerGames

  • Junior Playmaker
  • **
  • Posts: 53
Re: Replace String's Wild Card Charas With...
« Reply #3 on: August 07, 2018, 06:30:01 PM »
What you can do is use the String Replace Action.
This way you can change a word in your string at runtime. You will need to build the string as a local or global variable and then use string replace to change your wildcards.
Eg. "This is a great [item]" -> Set as string variable (Local or Global)
Replace string action -> [item] to your variable

Realistically your probably really looking for something like Dialog System on the asset store. This has playmaker integration and is very robust.
https://assetstore.unity.com/packages/tools/ai/dialogue-system-for-unity-11672

westingtyler

  • Sr. Member
  • ****
  • Posts: 277
    • My Video Game Projects Web Site
Re: Replace String's Wild Card Charas With...
« Reply #4 on: August 07, 2018, 06:43:40 PM »
hey, thanks. I will try string replace and see if it works. I actually bought the dialogue system on the asset store but found it limited. a fantastic asset, but I realized that for most of my systems I need to make them custom because I need to do things that are not standard or common, and in some cases things I've never seen done before.