Here is an example if you want it to affect
all dialogue in your game, it filters all the text, splits it to words and obfuscates/changes the font of the unknown words. In this example it's changing the text to red, but you can easily alter the tags being applied, just take care to note the double
{{ and
}} nescessary due to using the
format method.
Words can be "learnt" by adding them to the global
learnt set.
If you only want this logic applied to certain lines or areas of text then this approach could be married to custom text tag concept suggested by
hell_oh_world, however that would require a more complex function in order to correctly deal with the already parsed text tags. Very doable, but I wouldn't say trivial. A middle ground might be limiting it to the speech of certain characters, which I believe should be possible, but can't recall off the top of my head how to do so.
Hope this helps! :)
Code: Select all
default learnt = set()
init python hide:
import re
word = re.compile(r'(\w+)')
unknown = '{{color=f00}}{}{{/color}}'
def say_menu_text_filter(text):
return ''.join(t if t.lower() in learnt else unknown.format(t)
for t in word.split(text))
config.say_menu_text_filter = say_menu_text_filter
label start:
scene
'This is the first line of the test.'
$ learnt.update(('this', 'test'))
'This is the second line of the test.'
$ learnt.update(('of', 'the'))
'This is the third line of the test.'
$ learnt.add('is')
'This is the fourth line of the test.'
$ learnt.add('line')
'This is the fifth line of the test.'
return
n.b. This will mark any non-word characters as "unknown", but it should be easy enough to resolve that if it's a problem.