Neutral ATL transform aka Identity transform (to use as default argument)

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
komehara
Regular
Posts: 36
Joined: Fri Jan 31, 2020 10:08 pm
Projects: Spirit Link
Tumblr: hsandt
Deviantart: hsandt
Github: hsandt
itch: komehara
Contact:

Neutral ATL transform aka Identity transform (to use as default argument)

#1 Post by komehara »

I'm passing an ATL transform to a parameter label so I can customise the way I display a BG image:

Code: Select all

label show_bg(bg_name, tr=None):
        show expression "bg " + bg_name at tr
However, I noticed that my default value of None causes an error:
TypeError: 'NoneType' object is not callable
So, the most logical would be to pass a "neutral" or "identity" transform that does nothing, when I want to show the BG as such.

This doesn't seem to be defined natively, which means I need to define my own dummy transform that does nothing:

Code: Select all

transform identity:
        pass
and use it as default value.

Or, in order to support both passing a transform and no transform, create two cases:

Code: Select all

label show_bg(bg_name, tr=None):
    if tr:
        show expression "bg " + bg_name at tr
    else:
        show expression "bg " + bg_name
which is more verbose.

UPDATE: tested both methods, they do work

Post Reply

Who is online

Users browsing this forum: Lucyper