Splitting up long NVL text

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
Ryue
Miko-Class Veteran
Posts: 745
Joined: Fri Nov 02, 2012 8:41 am
Projects: Red eyes in the darkness
Contact:

Splitting up long NVL text

#1 Post by Ryue »

I found myself in trouble when using NVL because I always came below the limit for the window when I posted something. Furthermore
when I did the text line by line it was hard to send it to the editor and get it back again and reformat it.

Thus I wrote the code below so that I can use long texts from one talker and split it onto multiple nvl clear pages programmatically.


Known issues: \n (new line) can prove troublesome.

Code: Select all

init -50 python:
    def LongNVLText(talker, text):
        text = text.strip()
        splittedText = []

        maxPageLength = 947 # Max. number of chars per page
        
        while (len(text) > maxPageLength):
            foundBlankPosition = text.rfind(' ', 0, maxPageLength + 1)
        
            if (foundBlankPosition < 0):
                foundBlankPosition = maxPageLength + 1 # If no blank present then print all you get
                
                
            subText = text[0:foundBlankPosition + 1]
                
            splittedText.append(subText)
                
            text = text[foundBlankPosition:].strip()
            
        if (len(text) > 0):
            splittedText.append(text) # Print all remaining text
        
        totalTextPages = len(splittedText)
        currentPage = 0
        
        for printText in splittedText:
            currentPage = currentPage + 1

            if (len(printText) > 0): # Only print something if there is something to print
                talker(printText)
            
                if (currentPage < totalTextPages): # New page!
                    nvl_clear()
Usage:

Code: Select all

$narration = new Character(.....)
#Array and multiple lines only used for readability. They have no effect on the text printed.
$LongNVLText(narration, (
    "blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. "
    "blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. "
    "blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. "
    "blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. "
    "blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. "
    "blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. "
    "blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. "
    "blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. "
    "blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. "
    "blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. "
    "blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. blah blupp blah. "
))
Last edited by Ryue on Sun Jul 17, 2016 10:48 am, edited 1 time in total.

User avatar
chocoberrie
Veteran
Posts: 254
Joined: Wed Jun 19, 2013 10:34 pm
Projects: Marshmallow Days
Contact:

Re: Splitting up long NVL text

#2 Post by chocoberrie »

This looks really helpful, awesome! :D

If there is a lot of NVL text, trying to check the placement of every /n to make sure it's correct (or fixing them if there's errors) would be irritating...

So where would you put this? I'm assuming before the start label, right? (Or in another script file?) :)

Ryue
Miko-Class Veteran
Posts: 745
Joined: Fri Nov 02, 2012 8:41 am
Projects: Red eyes in the darkness
Contact:

Re: Splitting up long NVL text

#3 Post by Ryue »

chocoberrie wrote:This looks really helpful, awesome! :D

If there is a lot of NVL text, trying to check the placement of every /n to make sure it's correct (or fixing them if there's errors) would be irritating...

So where would you put this? I'm assuming before the start label, right? (Or in another script file?) :)
Hi
The next thing I would like is it to also recognize and process \n inside the text......but not sure how to tackle that one atm.

That aside I updated the script above to also include how the whole file looked like. I put it into its separate file called utiles.rpy (used to putting things into separate files).

Post Reply

Who is online

Users browsing this forum: Google [Bot]