snozbot / fungus

An easy to use Unity 3D library for creating illustrated Interactive Fiction games and more.
MIT License
1.59k stars 291 forks source link

Access "Story Text" in a Say command by editing the Say command script? #1039

Open holzfella opened 2 years ago

holzfella commented 2 years ago

Hey guys,

I want to create a method which looks for certain keywords within a "Say-text" and then change that word to something else. So far I came up with the idea to edit the "base scripts" and add methods in there which do that automatically before the Say dialogue is typed out. Is that even possible? Can I modify the base scripts at all?

I already tried something similar in the Character script: I added a string variable called "Character Pronoun" but it won't show up in the inspector (and yes, it's a Serialize Field already).

I'm not a coding pro. I know there are certain types of classes/scripts which can only be edited via some code words and methods. So my guess is the same applies to the Fungus scripts/classes.

Does anyone have any idea on how to do that? Or perhaps another idea on how to search the Story Text field within the Say command for certain words?

breadnone commented 2 years ago

Hi, you can do that by exposing the text field in the Say command to public, then recursively pool every Say commands in a single block or even multiple blocks then SubString your way from there. Good luck!

holzfella commented 2 years ago

Hi, you can do that by exposing the text field in the Say command to public, then recursively pool every Say commands in a single block or even multiple blocks then SubString your way from there. Good luck!

Hey, thanks for the reply! I think I figured out an easier approach to this: you can actually access/use variables in a Say text itself by using {$VarName} where a variable should get replaced by one that is set "beforehand" (like the main character's name)