Page 1 of 1

Automatically clear nvl text [Solved]

Posted: Tue Apr 14, 2015 8:32 am
by ForklessAnon
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

Re: Automatically clear nvl text

Posted: Tue Apr 14, 2015 12:39 pm
by philat
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.

Re: Automatically clear nvl text

Posted: Tue Apr 14, 2015 1:19 pm
by ForklessAnon
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

Re: Automatically clear nvl text

Posted: Tue Apr 14, 2015 2:05 pm
by philat

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.

Re: Automatically clear nvl text

Posted: Wed Apr 15, 2015 12:11 am
by ForklessAnon
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]]