Bug with munging filenames with -

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
Cynebeald
Regular
Posts: 45
Joined: Fri Feb 27, 2009 10:51 am
Projects: Enmaku
Contact:

Bug with munging filenames with -

#1 Post by Cynebeald »

It looks like label munging is broken if the file contains any weird characters. For example, in part4-something.rpy, the following error happens:
On line 44 of part4-something.rpy: expected ':' not found.
label _m1_part4-something__init_variables:

Ren'Py Version: Ren'Py 6.8.1a
Something like this should fix it, but I can't test it at the moment because my whole renpy installation broke down because of PyDev being too smart and recompiling stuff (goes in parser.py):

Code: Select all

import string

Code: Select all

# this contains a translation table used to get rid of characters not
# allowed in labels
munge_trans = string.maketrans(" -","__")

def munge_filename(fn):
    # The prefix that's used when __ is found in the file.
    rv = os.path.basename(fn)
    rv = os.path.splitext(rv)[0]    
    rv = rv.translate(munge_trans)
    return "_m1_" + rv + "__"
Update: Added import, use qualified name in maketrans call

chronoluminaire
Eileen-Class Veteran
Posts: 1153
Joined: Mon Jul 07, 2003 4:57 pm
Completed: Elven Relations, Cloud Fairy, When I Rule The World
Tumblr: alextfish
Skype: alextfish
Location: Cambridge, UK
Contact:

Re: Bug with munging filenames with -

#2 Post by chronoluminaire »

Seems to me the problem here is simply that your label contains a "-" character, and that's not allowed. This seems to fall into the category of "Doctor, it hurts when I do this" / "Then don't do that" solutions. :)
I released 3 VNs, many moons ago: Elven Relations (IntRenAiMo 2007), When I Rule The World (NaNoRenO 2005), and Cloud Fairy (the Cute Light & Fluffy Project, 2009).
More recently I designed the board game Steam Works (published in 2015), available from a local gaming store near you!

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: Bug with munging filenames with -

#3 Post by PyTom »

Well, we don't explicitly disallow it. So I will be fixing this in the next version of Ren'Py. I'll probably use a whitelist and escape all non-whitelist characters, rather than a blacklist on '-' and ' '.
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

Cynebeald
Regular
Posts: 45
Joined: Fri Feb 27, 2009 10:51 am
Projects: Enmaku
Contact:

Re: Bug with munging filenames with -

#4 Post by Cynebeald »

PyTom wrote:Well, we don't explicitly disallow it. So I will be fixing this in the next version of Ren'Py. I'll probably use a whitelist and escape all non-whitelist characters, rather than a blacklist on '-' and ' '.
Cool, that might also solve the case when there are two file names called the same, but placed in different directories (personally, I haven't run into this, but the code looks like it uses just the filename and not the path relative to the game directory). Then again, I don't think that too many games use this, so it's probably not worth the effort. Maybe it could be used by JQuartz's menu editor, instead of using a manual prefix. Does munging work for variable and function names too?

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: Bug with munging filenames with -

#5 Post by PyTom »

Yes, munging works everywhere except inside strings. It's actually applied before the script is parsed into Ren'Py and Python code.
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

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot]