Automatically clear nvl text [Solved]

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
ForklessAnon
Regular
Posts: 49
Joined: Fri Sep 06, 2013 1:13 am
Contact:

Automatically clear nvl text [Solved]

#1 Post by ForklessAnon » Tue Apr 14, 2015 8:32 am

I've been doing some tests on reducing needed code for the story scripts of my game. I'm looking at a way to remove the need to have "nvl clear" by having it automatically run nvl_clear() after a certain amount of lines have been displayed. I've tried a few ways to accomplish this (nvl_clear() on character callback, looking at setting flags in the scry, etc) and the only way I've been able to make it work without an out of range index error is

Code: Select all

### Function for callback hooks for NVL character dialogues ###
    def nvlsayhooks(event, interact=True, **kwargs):
        if not interact:
            return
        if event == "begin":
            if info.nvl_cleared is True:
                store.nvl_list = [store.nvl_list[-1]]
                info.nvl_cleared = False
        elif event == "end":
            if len(store.nvl_list) > 4:
                store.nvl_list = [store.nvl_list[-1]]
                info.nvl_cleared = True
This almost works with the exception of a bug that occurs in rollback where the last statement before the autoclear appears above the first statement after the autoclear. The reason for the bug is obvious when you look at the above code.
I was hoping someone would have an idea on how to properly clear the NVL list automatically after a certain number of lines.

This is not a necessity, merely a functionality I would like to have. Any help is appreciated.

Edit: The error I get with any other method is:

Code: Select all

IndexError('list index out of range',)

Full traceback:
  File "game/script.rpy", line 119, in script
    anon_nvl "You really don't know what you are doing, do you?"
  File "C:\Program Files (x86)\Renpy\renpy\ast.py", line 593, in execute
    renpy.exports.say(who, what, interact=self.interact)
  File "C:\Program Files (x86)\Renpy\renpy\exports.py", line 999, in say
    who(what, interact=interact)
  File "C:\Program Files (x86)\Renpy\renpy\character.py", line 829, in __call__
    self.do_done(who, what)
  File "renpy/common/00nvl_mode.rpy", line 288, in do_done
    nvl_list[-1][2]["what_args"]["alt"] = ""
IndexError: list index out of range
Last edited by ForklessAnon on Wed Apr 15, 2015 12:37 am, edited 2 times in total.

philat
Eileen-Class Veteran
Posts: 1606
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Automatically clear nvl text

#2 Post by philat » Tue Apr 14, 2015 12:39 pm

I tried running your code (with a minor edit to make nvl_cleared a regular global variable). It seems to work fine with rollback for me.

ForklessAnon
Regular
Posts: 49
Joined: Fri Sep 06, 2013 1:13 am
Contact:

Re: Automatically clear nvl text

#3 Post by ForklessAnon » Tue Apr 14, 2015 1:19 pm

philat wrote:I tried running your code (with a minor edit to make nvl_cleared a regular global variable). It seems to work fine with rollback for me.
Here's a video that displays the rollback bug when using said solution: http://puu.sh/hdQf7/2d9d3d13b3.mp4

philat
Eileen-Class Veteran
Posts: 1606
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Automatically clear nvl text

#4 Post by philat » Tue Apr 14, 2015 2:05 pm

Code: Select all

init:
    define e = Character('Eileen', kind=nvl, callback=nvlsayhooks, color="#c8ffc8")

init -1 python:
    nvl_cleared = False

    def nvlsayhooks(event, interact=True, **kwargs):
        global nvl_cleared
        if not interact:
            return
        if event == "begin":
            if nvl_cleared is True:
                store.nvl_list = [store.nvl_list[-1]]
                nvl_cleared = False
        elif event == "end":
            if len(store.nvl_list) > 4:
                store.nvl_list = [store.nvl_list[-1]]
                nvl_cleared = True
https://dl.dropboxusercontent.com/u/487 ... 52-394.mp4

Like I said, I'm not seeing that issue.

ForklessAnon
Regular
Posts: 49
Joined: Fri Sep 06, 2013 1:13 am
Contact:

Re: Automatically clear nvl text

#5 Post by ForklessAnon » Wed Apr 15, 2015 12:11 am

philat wrote:Like I said, I'm not seeing that issue.
Alright so it's something else in my code that's being screwy. Thanks for the help.

Edit: Turns out that the info object was mucking up the rollback state for some reason. It works now.

Edit2: MUCH simpler way that I should have used from the begining.

Code: Select all

### Function for callback hooks for NVL dialogue ###
    def nvlsayhooks(event, interact=True, **kwargs):
        if not interact:
            return
        if event == "begin":
            if len(store.nvl_list) > 5: #total number of lines needed to have been shown before clearing
                store.nvl_list = [store.nvl_list[-1]]

Post Reply

Who is online

Users browsing this forum: No registered users