feature req: call_in_new_context doesn't trim label names

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
Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

feature req: call_in_new_context doesn't trim label names

#1 Post by Jake »

As seen in this thread, it seems renpy.call_in_new_context doesn't trim the name of the label that's passed in - meaning that if there's a trailing or leading space, the call fails.

Admittedly there shouldn't be a trailing or leading space, but since labels can't have trailing or leading spaces anyway, it doesn't seem to me that there's any value in not trimming the input, and it would help out in circumstances like that one.
Server error: user 'Jake' not found

LordShiranai
Regular
Posts: 188
Joined: Wed Jul 07, 2010 5:49 pm
Completed: Mobile Food Madness, Super Otome Quest
Location: Pacific Northwest
Contact:

Re: feature req: call_in_new_context doesn't trim label name

#2 Post by LordShiranai »

Just curious. Do other methods that take a label such as renpy.jump or ui.callsinnewcontext automatically strip trim? If so, I would agree that renpy.call_in_new_context should behave in a similar manner for consistency.
Don't Blame Me. I Voted for Vermin Supreme.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: feature req: call_in_new_context doesn't trim label name

#3 Post by PyTom »

No, we never strip labels - I don't think we should, since there's an admittedly slight performance cost.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

Re: feature req: call_in_new_context doesn't trim label name

#4 Post by Jake »

PyTom wrote:I don't think we should, since there's an admittedly slight performance cost.
Leaving aside that it's a very minor cost at a point where it's very unlikely to make any significant difference, couldn't something like this feasibly even be done as a precompiler step, at least for string-literal parameters to those functions?

I realise it's a bit of a fringe case anyway, but it's things like this which do confuse people who aren't used to programming - the idea that "blah" is different from " blah" is quite an odd concept to a lot of people.
Server error: user 'Jake' not found

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: feature req: call_in_new_context doesn't trim label name

#5 Post by PyTom »

I don't think it could be done as a precompiler step, as we don't have any real understanding of functions until just before they're run. (This is python, so there isn't a static analysis phase to speak of.)

It's also a sort of regularity thing. If " foo" matches "foo" when we go to call a label, then why wouldn't " Jake" match "Jake" in code like:

Code: Select all

$ name = " Jake"
if name == "Jake":
    ...
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

Re: feature req: call_in_new_context doesn't trim label name

#6 Post by Jake »

PyTom wrote: It's also a sort of regularity thing. If " foo" matches "foo" when we go to call a label, then why wouldn't " Jake" match "Jake" in code like:
Because when you're jumping to a label it's entirely possible to work out whether or not the spaces are valid (because they always aren't, and will never be intentional) and when you're doing arbitrary operations on strings it's not possible.

As the old saying goes - be liberal in what you accept, and conservative in what you do.
Server error: user 'Jake' not found

iichan_lolbot
Veteran
Posts: 206
Joined: Tue Dec 30, 2008 9:18 am
Projects: iichan erogame
Contact:

Re: feature req: call_in_new_context doesn't trim label name

#7 Post by iichan_lolbot »

Jake, you can just call

Code: Select all

renpy.call_in_new_context(x.strip(" ").rstrip(" "))
instead of

Code: Select all

renpy.call_in_new_context(x)
But it wouldn't save you from troubles like tabs or newline symbols. Also it is still case sensitive, etc. =)

Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

Re: feature req: call_in_new_context doesn't trim label name

#8 Post by Jake »

iichan_lolbot wrote:Jake, you can just call
I know. And I wouldn't pass a label name with spaces in the first place, because I know what I'm doing.

I started the thread 'cause a guy who wasn't a programmer was trying to use a Cookbook script and had left a space in the string, and it occurred to me that there was no reason Ren'Py couldn't strip it, since spaces aren't valid parts of label names anyway... and therefore, it would be better and more useful for newbies to strip.
Server error: user 'Jake' not found

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]