Page 1 of 1

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

Posted: Sun May 30, 2021 10:03 am
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?

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

Posted: Sun May 30, 2021 2:52 pm
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/

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

Posted: Fri Jun 18, 2021 2:46 pm
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.