"Subclassing" characters - modifying pre-existing chars

A place to discuss things that aren't specific to any one creator or game.
Forum rules
Ren'Py specific questions should be posted in the Ren'Py Questions and Annoucements forum, not here.
Post Reply
Message
Author
User avatar
Musashi
Regular
Posts: 57
Joined: Mon Feb 22, 2010 10:04 am
Projects: Yesoidos
Contact:

"Subclassing" characters - modifying pre-existing chars

#1 Post by Musashi »

I've got two questions about creating and organizing characters.

First:
I'm trying to display quotes from a book with citations using the centered character, but I want to customize the behavior. So far, I've got something like this:

Code: Select all

    centered "{i}Tsadikim are motivated [solely] by their good nature, as it is written, \"My heart is a void within me,\" i.e., void of an evil nature....{/i}{p}{p}- Collected Sayings, {i}Master Shneur Zalman of Liadi{/i}{fast}"
But that's a mouthful, and it's hard to read the code because the text can get buried in formatting directives. Since I'm going to be using this at the beginning of every chapter, I want to prepackage the formatting somehow. Any ideas?

Second:
If I want special formatting to apply to all my characters, I'd like to be able to copy and modify a default character that already has most of the formatting information (positioning, suffixes, click-to-continue markers, etc.). How do I do this?

number473
Regular
Posts: 195
Joined: Tue Dec 15, 2009 4:20 am
Projects: The Duke's Daughter
Location: Cape Town
Contact:

Re: "Subclassing" characters - modifying pre-existing chars

#2 Post by number473 »

For the second question, you could be looking for Character.copy(). See http://renpy.org/wiki/renpy/doc/referen ... Characters.

Code: Select all

template = Character("", lots of stuff goes here)
a = template.copy("A")
b = template.copy("B")
## and so on
Mental weather report: Cloudy with a possibility of brain storms.

User avatar
Musashi
Regular
Posts: 57
Joined: Mon Feb 22, 2010 10:04 am
Projects: Yesoidos
Contact:

Re: "Subclassing" characters - modifying pre-existing chars

#3 Post by Musashi »

That's great, thanks! I'm having trouble using it on the centered character, though. This code gives me an error, saying that centered isn't defined:
$ quote = centered.copy(None, what_slow_cps=0, what_prefix="{i}", what_suffix="{/i}{p}{p}{nw}")
Do I have to create a centered character from scratch?
Image
(Work in progress)

prezzey
Regular
Posts: 42
Joined: Tue Jul 28, 2009 12:15 pm
Projects: Emerald Spires, Amesirun (ES side story)
Location: Austria/Hungary
Contact:

Re: "Subclassing" characters - modifying pre-existing chars

#4 Post by prezzey »

This is completely offtopic, but I just have to - are you making a game with the Alter Rebbe in it?!?! :shock: :mrgreen:


(edit: oops I used RenPy formatting instead of phpbb :D )
http://www.prezzey.net

"Manny, until now we scraped along the ground like rats, but from now on, we soar! Like eagles! Yeah! Like eagles... ON POGO STICKS!" - Grim Fandango

luminarious
Veteran
Posts: 353
Joined: Thu May 01, 2008 1:12 pm
Projects: Winter, winter
Location: Estonia
Contact:

Re: "Subclassing" characters - modifying pre-existing chars

#5 Post by luminarious »

number473 wrote:For the second question, you could be looking for Character.copy(). See http://renpy.org/wiki/renpy/doc/referen ... Characters.

Code: Select all

template = Character("", lots of stuff goes here)
a = template.copy("A")
b = template.copy("B")
## and so on
How is that different from defining a character and then using the 'kind' property? Like this:

Code: Select all

define actor = Character(" ", what_prefix='“', what_suffix='”')
define L = Character("Lelia", kind=actor)

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: "Subclassing" characters - modifying pre-existing chars

#6 Post by chronoluminaire »

Musashi wrote:That's great, thanks! I'm having trouble using it on the centered character, though. This code gives me an error, saying that centered isn't defined:
$ quote = centered.copy(None, what_slow_cps=0, what_prefix="{i}", what_suffix="{/i}{p}{p}{nw}")
Do I have to create a centered character from scratch?
I have no idea. According to the doc page linked earlier, the centered character should exist.
luminarious wrote:How is that different from defining a character and then using the 'kind' property? Like this:

Code: Select all

define actor = Character(" ", what_prefix='“', what_suffix='”')
define L = Character("Lelia", kind=actor)
It's not. It's another way to do the same thing.

As to Musashi's original first question: I don't think you'll be able to use a Character to standardise all of that formatting. I think you might have to do it with a function, something like:

Code: Select all

init python:
  def BookQuote(quotedText, bookName, authorName):
    string = "{i}" + quotedText + "{/i}{p}{p}- " + bookName + ", {i}" + authorName + "{/i}{fast}"
    renpy.say(centered, string)
    renpy.pause

label start:
  "Normal text"
  $ BookQuote("Tsadikim blah de blah", "Collected Sayings", "Master Shneur Zalman of Liadi")
  "Some more text"
Obviously if some of those bits are the same for every book quote, you can just make them part of the definition of string rather than passing them in as input arguments each time you call the function.
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
Musashi
Regular
Posts: 57
Joined: Mon Feb 22, 2010 10:04 am
Projects: Yesoidos
Contact:

Re: "Subclassing" characters - modifying pre-existing chars

#7 Post by Musashi »

Ok, so I have the formatting the way I want it:

Code: Select all

init:
    python:
        def BookQuote(text, source, title=""):
            if title != "":
                s = "{i}" + text + "{/i}{p}{p}- " + title + ", {i}" + source + "{/i}{fast}"
            else:
                s = "{i}" + text + "{p}{p}- " + source + "{/i}{fast}"
            renpy.transition(fade)
            renpy.say(centered, s)
            # renpy.pause   # didn't notice any difference w/ or w/o this
label start:
    $ BookQuote("Tsadikim are motivated [solely] by their good nature, as it is written, \"My heart is a void within me,\" i.e., void of an evil nature....",
    "Master Shneur Zalman of Liadi",
    "Collected Sayings")
    $ BookQuote("The Almighty saw that the tsadikim were few so He planted them in every generation.",
    "Gemoro, Yoima 38b")
Problem is, the fade transition only works properly the first time. It fades out the main menu and then fades in the text, but after the first BookQuote(), fade out stops working, leaving just the fade in. What's happening?
Image
(Work in progress)

User avatar
Musashi
Regular
Posts: 57
Joined: Mon Feb 22, 2010 10:04 am
Projects: Yesoidos
Contact:

Re: "Subclassing" characters - modifying pre-existing chars

#8 Post by Musashi »

I figured out why the transitions didn't work.

Because I used the {fast} tag to display all the text at once, it disabled any following transitions. I decided to use a built-in ParameterizedText object called "text" instead. These objects are treated like images, so they appear all at once, and allow transitions before and after.

Now that the transition problem is solved, all that was left is the text formatting. After reading the renpy source code for the ParameterizedText object, I found out that the renpy parser would accept not just a quoted string, but any python expression that evaluated to a string. Including a function call.

So, here's how it goes:

Code: Select all

label start:
    scene black
    with slowDissolve # fade from main menu
    
    show text chapterText(number = 1, title = "Early Years") with dissolve
    pause
    scene black with dissolve
    show text bookText(
        text = "Tsadikim are motivated [solely] by their good nature, as it is written, \"My heart is a void within me,\" i.e., void of an evil nature....", 
        author = "Rabbi Shneur Zalmen of Liadi", 
        title = "Likkutei Amarim") with dissolve
    pause
    scene black with dissolve
As in regular python, the argument variable names may be left out, if you can remember the order of the arguments in the function definition:

Code: Select all

def bookText(text, author = None, title = None):        
    if author and title:
        return "{i}%s{/i}\n\n- {i}%s{/i}, %s" % (text, author, title)
    elif title:
        return "{i}%s{/i}\n\n- %s" % (text, title)
    elif title:
        return "{i}%s{/i}\n\n- {i}%s{/i}" % (text, author)
    else:
        return "{i}%s{/i}" % text


def chapterText(number = None, title = None):
    if not title and not number:
        raise Exception("chapterText() requires at least one argument")
    if not title:
        return "{size=+20}{i}Chapter %d{/i}{/size}" % number
    elif not number:
        return "{size=+20}{i}%s{/i}{/size}" % title
    else: # have both a number and a title
        return "{size=+10}{i}Chapter %d{/size}{size=+20}\n\n%s{/i}{/size}" % (number, title)
Image
(Work in progress)

Post Reply

Who is online

Users browsing this forum: No registered users