Counting the length of a character name
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.
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.
- solarProtag
- Regular
- Posts: 37
- Joined: Sun May 28, 2017 12:17 am
- Completed: http://solarprotag.weebly.com/gamedev.html
- Projects: Battle Live Series
- Tumblr: solarasketchbook
- itch: solarprotagonist
- Contact:
Counting the length of a character name
Hi there!
I've been trying to figure this out for a bit, but I keep coming out empty, but I want to count how long a character's name is so that I can use that to display appropriately-sized nameboxes without having to define a namebox image for each speaking character.
I've tried using len(who) but that only works for lists so it doesn't even run, and I've tried to convert the name string into a list but the engine hated that.
Thank you in advance!
I've been trying to figure this out for a bit, but I keep coming out empty, but I want to count how long a character's name is so that I can use that to display appropriately-sized nameboxes without having to define a namebox image for each speaking character.
I've tried using len(who) but that only works for lists so it doesn't even run, and I've tried to convert the name string into a list but the engine hated that.
Thank you in advance!
- IrinaLazareva
- Veteran
- Posts: 399
- Joined: Wed Jun 08, 2016 1:49 pm
- Projects: Legacy
- Organization: SunShI
- Location: St.Petersburg, Russia
- Contact:
Re: Counting the length of a character name
Nope. This method works for string type of data.solarProtag wrote: ↑Wed Apr 07, 2021 1:19 pmI've tried using len(who) but that only works for lists so it doesn't even run
Code: Select all
label start:
'test'
python:
a = 'hello word'
b = len(a)
'[a] [b]'
return
Code: Select all
if len(who)<=....bla bla
I guess the problem is something else..
- solarProtag
- Regular
- Posts: 37
- Joined: Sun May 28, 2017 12:17 am
- Completed: http://solarprotag.weebly.com/gamedev.html
- Projects: Battle Live Series
- Tumblr: solarasketchbook
- itch: solarprotagonist
- Contact:
Re: Counting the length of a character name
Yeah, for some reason no matter what I do the len() function refuses to count the "who" variable. It doesn't work for "what" either.
Re: Counting the length of a character name
Try to use Frame() as a background of the namebox instead of an image, so it will stretch/shrink automatically.solarProtag wrote: ↑Wed Apr 07, 2021 1:19 pm ... I want to count how long a character's name is so that I can use that to display appropriately-sized nameboxes without having to define a namebox image for each speaking character. ...
https://www.renpy.org/doc/html/displayables.html#Frame
- solarProtag
- Regular
- Posts: 37
- Joined: Sun May 28, 2017 12:17 am
- Completed: http://solarprotag.weebly.com/gamedev.html
- Projects: Battle Live Series
- Tumblr: solarasketchbook
- itch: solarprotagonist
- Contact:
Re: Counting the length of a character name
The thing is, that stretching is exactly what I don't want, as my goal is to have one namebox for names shorter than a certain number of letters, and one for names longer.Alex wrote: ↑Wed Apr 07, 2021 5:23 pmTry to use Frame() as a background of the namebox instead of an image, so it will stretch/shrink automatically.solarProtag wrote: ↑Wed Apr 07, 2021 1:19 pm ... I want to count how long a character's name is so that I can use that to display appropriately-sized nameboxes without having to define a namebox image for each speaking character. ...
https://www.renpy.org/doc/html/displayables.html#Frame
I've tolerated the stretching in my past games since I didn't care, but this time I'd like to see if I can make that happen.
Re: Counting the length of a character name
This code worked for me...solarProtag wrote: ↑Wed Apr 07, 2021 1:19 pm ...I've tried using len(who) but that only works for lists so it doesn't even run, and I've tried to convert the name string into a list but the engine hated that. ...
Code: Select all
screen say(who, what):
style_prefix "say"
window:
id "window"
if who is not None:
$ x = len(who)
window:
id "namebox"
style "namebox"
text who + str(x) id "who"
text what id "what"
Code: Select all
define e = Character("Eileen")
define x = Character("???")
label start:
e "..."
x "..."
- solarProtag
- Regular
- Posts: 37
- Joined: Sun May 28, 2017 12:17 am
- Completed: http://solarprotag.weebly.com/gamedev.html
- Projects: Battle Live Series
- Tumblr: solarasketchbook
- itch: solarprotagonist
- Contact:
Re: Counting the length of a character name
That is so weird then!
Anytime I've tried something like:
it won't update my variable. (and yes it's defined before this)
Anytime I've tried something like:
Code: Select all
if who is not None:
if len(who) <=5:
$ nameshort = True
else:
$ nameshort = False
window:
id "namebox"
style "namebox"
text who id "who"
Who is online
Users browsing this forum: No registered users