Changing something based on the length of a player input variable?

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
User avatar
parttimestorier
Veteran
Posts: 429
Joined: Thu Feb 09, 2017 10:29 pm
Completed: No Other Medicine, Well Met By Moonlight, RE:BURN, The Light at the End of the Ocean, Take A Hike!, Wizard School Woes
Projects: Seeds of Dreams
itch: janetitor
Location: Canada
Contact:

Changing something based on the length of a player input variable?

#1 Post by parttimestorier »

I'm working on a project in which players can input a custom name for the main character, and I'm currently experimenting with what the character limit on that should be. I'm wondering if I might be able to do something like make the text size smaller in the main character's dialogue label if it's past a certain length. That way players who want to give the character a longer name can still do it, and rather than cutting them off past the point where it would be bigger than the namebox, I just make their name smaller to fit. I've messed around with character-specific labels before by putting things like

Code: Select all

if _last_say_who == "mc":
    add "some_special_image_or_something.png" 
on the namebox screen before, so I know where to start with figuring out that part - but I'm not sure whether it's possible to set up an if/else statement that changes something based on the length of the variable text. I tried just throwing

Code: Select all

if mcfirst length == 8:
    "test"
into the code of a random scene to see if it would work, and it gave me an invalid syntax error. Does anyone know what I should be doing instead?
ImageImageImage

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2384
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Changing something based on the length of a player input variable?

#2 Post by Ocelot »

Code: Select all

if len(mcfirst) > 10:
    "You have rather long name. There might be display issues"
https://www.geeksforgeeks.org/python-string-length-len/
< < insert Rick Cook quote here > >

User avatar
parttimestorier
Veteran
Posts: 429
Joined: Thu Feb 09, 2017 10:29 pm
Completed: No Other Medicine, Well Met By Moonlight, RE:BURN, The Light at the End of the Ocean, Take A Hike!, Wizard School Woes
Projects: Seeds of Dreams
itch: janetitor
Location: Canada
Contact:

Re: Changing something based on the length of a player input variable?

#3 Post by parttimestorier »

Ocelot wrote: Sun May 30, 2021 2:52 pm

Code: Select all

if len(mcfirst) > 10:
    "You have rather long name. There might be display issues"
https://www.geeksforgeeks.org/python-string-length-len/
Thanks! That works perfectly.
ImageImageImage

Post Reply

Who is online

Users browsing this forum: Google [Bot]