(Solved) Changing the font color based on if the player has seen the text before?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
ImRikun
Newbie
Posts: 4
Joined: Fri Apr 09, 2021 5:32 pm
Contact:

(Solved) Changing the font color based on if the player has seen the text before?

#1 Post by ImRikun »

I'm currently working on a little project where the player can explore their village, like a choose your own adventure game. As the player explores, there's a random chance they'll stumble on one of many events. The problem is that I don't want the player to accidentally miss anything new as they are going through dialogue they've already read. Is there any way to mark text the player hasn't read in a different font color, so that they instantly see new content? I've included an example below.

First time:
You wander into the forest, there's a pleasant smell of pine coming from the tall trees surrounding you. You lay down and take a small break, enjoying the atmosphere. After a while, you stand up and decide to be on your way.

Second Time:
You wander into the forest, there's a pleasant smell of pine coming from the tall trees surrounding you. You lay down and take a small break, enjoying the atmosphere. After a while, you stand up and decide to be on your way.

Third Time:
You wander into the forest, there's a pleasant smell of pine coming from the tall trees surrounding you. You lay down and take a small break, enjoying the atmosphere. Your eyelids feel heavy and you decide to take a little nap, once you wake up you notice a squirrel sitting on your chest, your movement scares it off and it drops what it was holding, an odd looking key. After a while, you stand up and decide to be on your way.

Hopefully that explains what I mean, apologies if this is something really basic, the only way I know how to do this would be with individual variables, and that doesn't sound very efficient! :lol: Hopefully someone can offer a more elegant solution, thank you for the help!
Last edited by ImRikun on Sun Apr 11, 2021 8:08 am, edited 1 time in total.

uncoded
Regular
Posts: 27
Joined: Fri Apr 09, 2021 10:29 am
Contact:

Re: Changing the font color based on if the player has seen the text before?

#2 Post by uncoded »

Maybe something along the lines of :
  1. put each line of dialogue you want to be remembered in as specific label.
  2. in each label, display your successive dialogue lines, ie. the whole text "thread" up to the moment the user has to make a choice. Then (before doing anything other, like displaying menu choices, jumping or anything), you add your label name to a global list or map that stores the "already read" threads.
  3. at the beginning of each thread you conditionnaly display texts with a different font style depending on if the label you just entered.
Quite a hassle if your text has many dialogues paths, but that should work.
Maybe Ren'Py has hooks you can use to customise stuff that is done each time you enter/leave a label? idk, but if it exists, doing steps 1. and 2. there would be appropriate.
🐾

ImRikun
Newbie
Posts: 4
Joined: Fri Apr 09, 2021 5:32 pm
Contact:

Re: Changing the font color based on if the player has seen the text before?

#3 Post by ImRikun »

Thank you for the suggestion! I might have to do it that way if there's no other way around it. I think Renpy keeps note of what text the player has already read in the "persistent" file in the saves folder, so technically the data I need should be on there, the problem is how to use it...

uncoded
Regular
Posts: 27
Joined: Fri Apr 09, 2021 10:29 am
Contact:

Re: Changing the font color based on if the player has seen the text before?

#4 Post by uncoded »

You're right, persistent data is a thing.

I did a test for you with a fresh project cleaned of all persistent data ; here is my game/script.rpy file:

Code: Select all

label start:
    python:
        print(renpy.game.persistent._seen_ever)
    "Let's do this"
    python:
        print(renpy.game.persistent._seen_ever)
Output:

Code: Select all

{u'_call__load_reload_game_1': True, u'_invoke_main_menu': True, u'_main_menu_screen': True, u'_main_menu': True, u'main_menu_screen': True, (u'renpy/common/00gltest.rpy', 1615434093, 590): True, u'_gl_test': True, u'_errorhandling': True, u'_start_store': True, u'start': True, u'_load_reload_game': True, u'_style_reset': True, u'_start': True}
{u'_call__load_reload_game_1': True, u'_invoke_main_menu': True, u'_main_menu_screen': True, u'_main_menu': True, u'main_menu_screen': True, (u'renpy/common/00gltest.rpy', 1615434093, 590): True, u'_gl_test': True, u'_errorhandling': True, u'_start_store': True, u'start': True, u'_load_reload_game': True, (u'game/script.rpy', 1618059234, 1): True, u'_style_reset': True, u'_start': True}
Thus, it seems to me that line of dialogue "Let's do this" in my game/script.rpy file coresponds to entry (u'game/script.rpy', 1618059234, 1).

I closed game and reran it, and output was exactly the same, so this seems to count occurences of this line of dialogue during this specific game. Unique id 1618059234 seems even to be consistent across all runs of a given game, if this is relevant.

Thus using renpy.game.persistent._seen_ever[<CURRENT_ID>] seems part of what your solution.
🐾

ImRikun
Newbie
Posts: 4
Joined: Fri Apr 09, 2021 5:32 pm
Contact:

Re: Changing the font color based on if the player has seen the text before?

#5 Post by ImRikun »

Thank you for the help! I did a bit of experimentation and googling, and I actually found someone who had done something similar before! I'll put the link to the post below, I'll need to do a bit of tweaking of the code but it looks like it will work great! viewtopic.php?f=8&t=24322

Post Reply

Who is online

Users browsing this forum: Google [Bot], Tomoyo Ichijouji