Tabbing the text

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
EvilDragon
Veteran
Posts: 284
Joined: Fri Dec 28, 2007 5:47 am
Location: Where the Dragons rule!
Contact:

Tabbing the text

#1 Post by EvilDragon »

I need some help again :D

How can I achieve Tsukihime-style text tabbing like this:

Code: Select all

This...
         Is...
               Really...
                          Strange!
Adding spaces in say doesn't seem to do the trick the way it should, nor would I like to have a different character for every tabstop. Isn't there a character like \n that can tab a number of whitespace characters in? Also, non-monospaced font is in question, if it means anything to you.
Angels of paradise, angels of sacrifice
Please let me be under your wings...

User avatar
PyTom
Ren'Py Creator
Posts: 16093
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: Tabbing the text

#2 Post by PyTom »

We don't support tabbing directly. By default, Ren'Py compresses runs of whitespace into single spaces, but you can backslash escape them to fix that.

"No spaces\n
\ \ \ \ Four Spaces\n
\ \ \ \ \ \ \ \ Eight spaces\n
\ \ \ \ \ \ \ \ \ \ \ \ etc."
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

EvilDragon
Veteran
Posts: 284
Joined: Fri Dec 28, 2007 5:47 am
Location: Where the Dragons rule!
Contact:

Re: Tabbing the text

#3 Post by EvilDragon »

This does the trick, thanks!
Angels of paradise, angels of sacrifice
Please let me be under your wings...

herenvardo
Veteran
Posts: 359
Joined: Sat Feb 25, 2006 11:09 am
Location: Sant Cugat del Vallès (Barcelona, Spain)
Contact:

Re: Tabbing the text

#4 Post by herenvardo »

I saw this thread just now and I want to make a suggestion: if you only need the tabing on one or two statements, escaping spaces directly might be fine; but if you're doing it too often it might render your code almost unreadable. In such case, my custom text tag parser (click this link to find it) could enable a more readable approach... if you want to try it, you should include the module (the ctextags.rpym file) in your game directory, then add something like this in an init block:

Code: Select all

init:
    python:
        renpy.load_module("ctextags") # Loads the Custom Text Tags module
        def tab(arg, text): # This function will handle the custom {tab=something} tag
            return " " * int(arg)
        custom_text_tags["tab"] = (False, tab) # "Registers" the function, pairing it with the "{tab}" tag
        config.say_menu_text_filter = cttfilter # Kindly asks Ren'py to parse our custom tags on every say and menu statement
Then, a code like PyTom's example
PyTom wrote:"No spaces\n
\ \ \ \ Four Spaces\n
\ \ \ \ \ \ \ \ Eight spaces\n
\ \ \ \ \ \ \ \ \ \ \ \ etc."
would become:

Code: Select all

"No spaces\n
{tab=4}Four Spaces\n
{tab=8}Eight spaces\n
{tab=12}etc."
In both cases, the output would be something like this:

Code: Select all

No spaces
    Four Spaces
        Eight spaces
            etc.
As a side note I'd like you to notice that the tab() function does not escape the spaces: doing so was causing the backslashes to appear on the screen; so I guessed that config.say_menu_text_filter is called after the escapes are replaced... fortunatelly, by when it's called whitespace is already trimmed, so the spaces introduced by the function won't be trimmed again :P
Also, I'd like to mention that this is exactly the kind of task my module is aimed to handle.
Finally, I've to insist that whether directly escaping the spaces in your statements or using a custom tag would be best depends only in how often do you need to tab your text.
I have failed to meet my deadlines so many times I'm not announcing my projects anymore. Whatever I'm working on, it'll be released when it is ready :P

EvilDragon
Veteran
Posts: 284
Joined: Fri Dec 28, 2007 5:47 am
Location: Where the Dragons rule!
Contact:

Re: Tabbing the text

#5 Post by EvilDragon »

Wow, that's a very nifty solution! I was actually wondering how come such a thing isn't already there in ren'py, since \ \ 's would really mess up the reading of the code. Thanks for this, I'll definitely use it a lot!
Angels of paradise, angels of sacrifice
Please let me be under your wings...

monele
Lemma-Class Veteran
Posts: 4101
Joined: Sat Oct 08, 2005 7:57 am
Location: France
Contact:

Re: Tabbing the text

#6 Post by monele »

I don't have a precise use for this tag add-on right now, but I know I will at some point so... is it up on the wiki or somewhere easy to find? I don't want to miss it once the threads have been buried in the depth of the forums :)

EvilDragon
Veteran
Posts: 284
Joined: Fri Dec 28, 2007 5:47 am
Location: Where the Dragons rule!
Contact:

Re: Tabbing the text

#7 Post by EvilDragon »

I agree, Herenvardo, post this to cookbook!
Angels of paradise, angels of sacrifice
Please let me be under your wings...

herenvardo
Veteran
Posts: 359
Joined: Sat Feb 25, 2006 11:09 am
Location: Sant Cugat del Vallès (Barcelona, Spain)
Contact:

Re: Tabbing the text

#8 Post by herenvardo »

I must say that I was reluctant to add this to the cookbook for licensing reasons (I had good reasons to make the original release under the LGPL). But after some deep thinking about the topic, I realize that the more "relaxed" ren'py license is not much of a problem: the potential abuses I wanted to prevent with the LGPL will simply not happen within the Ren'py community. So, here it is: http://www.renpy.org/wiki/renpy/doc/coo ... _text_tags
I have failed to meet my deadlines so many times I'm not announcing my projects anymore. Whatever I'm working on, it'll be released when it is ready :P

monele
Lemma-Class Veteran
Posts: 4101
Joined: Sat Oct 08, 2005 7:57 am
Location: France
Contact:

Re: Tabbing the text

#9 Post by monele »

I'm not sure how posting this in the cookbook changes its license but... in any case, thanks ^_^

User avatar
PyTom
Ren'Py Creator
Posts: 16093
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: Tabbing the text

#10 Post by PyTom »

Well, stuff posted to the wiki is contributed under the Ren'Py (MIT) license, so I can distribute it along with Ren'Py. So if you were to post your code there, the licensing would be weird to say the least.
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

monele
Lemma-Class Veteran
Posts: 4101
Joined: Sat Oct 08, 2005 7:57 am
Location: France
Contact:

Re: Tabbing the text

#11 Post by monele »

Ohh... I didn't know that. In that light, I see how it's a problem ô_o;...

Post Reply

Who is online

Users browsing this forum: Bing [Bot]