Trying to change the contents of a "show text" command

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
DavidCF77
Newbie
Posts: 9
Joined: Mon Aug 16, 2021 12:45 pm
Deviantart: DavidCF77
Github: DavidCF77
itch: DavidCF
Contact:

Trying to change the contents of a "show text" command

#1 Post by DavidCF77 »

Hi,
I am trying to use the following .rpy file to make a change on the contents of a "show text" command but with no success.
If the string was just "This is Fred..." the change would work.
Can you please tell me what am I missing?
Thank you.
David

init 9999 python:

import re

# def replace_text(t1):
def say_menu_text_filter(t1):

t1 = re.sub("Fred", r'[mcName]', t1)
t1 = re.sub("FRED", r'\[mcName!u\]', t1)
# OR
t1 = t1.replace("Fred", "[mcName]")
t1 = t1.replace("FRED", "[mcName!u]")

return t1
config.say_menu_text_filter = say_menu_text_filter

config.label_overrides = {"start": "start_mod", "original_start": "start"}
# config.replace_text = replace_text

screen name_button():

## Ensure this appears on top of other screens.
zorder 100
hbox:
style_prefix "quick"
xalign 0.27
yalign 1.00

textbutton _("mcName") action ui.callsinnewcontext("start_mod") text_size 20

label start_mod():
menu:
"Rename":
$ mcName = renpy.input("Enter your name:", "").strip()
$ f = Character("[mcName]", color = "#F01711")
"Name changed to [mcName]"
jump original_start
"Default":
$ mcName = "Fred"
$ f = Character("[mcName]", color="#F01711")
"Default name - [mcName]"
jump original_start

#I am trying to make changes to the contents of this renpy line
# if the line was just "This is Fred..." it works.
# It is the "show text" that seems to be the problem.

label start:
show text "This is Fred..." with dissolve

User avatar
ISAWHIM
Veteran
Posts: 318
Joined: Sun Nov 06, 2016 5:34 pm
Contact:

Re: Trying to change the contents of a "show text" command

#2 Post by ISAWHIM »

You need to make a "REPLACE" for "show text" also... as opposed to "say"

The code only replaces text in the renpy.say command. You need one for renpy.show and somehow the sub-command "text". (renpy.show_text)???

What are you trying to do? You should be using variables to identify "FRED", not text...

When a user creates a name, that is saved as a value, like this... none of that "replace" garbage is needed.

Code: Select all

$mcname = "Fred"
show text "This is [mcname]..."
You could have this ALSO be the default characters name, so it is easy for you..., $FRED and "[FRED]", as opposed to $YOU and "[YOU]".

Personally, I use a more complex setup... YOU.NAME, so I can also have YOU.LOCATION, and YOU.MOOD, and YOU.HUNGER, and YOU.ENERGY, etc...

I am sure there is a way to make it (uppercase).UCASE, when needed, inline. If not, you can make another value for that single specific option. $mcnameCAPS

Post Reply

Who is online

Users browsing this forum: Google [Bot]