Readback - Excluding 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
User avatar
Discostar
Regular
Posts: 40
Joined: Mon Mar 10, 2014 10:29 am
Contact:

Readback - Excluding Text?

#1 Post by Discostar »

Is there a way to exclude text from being recorded in the text history "readback"?

jw2pfd
Regular
Posts: 87
Joined: Tue Sep 18, 2012 9:55 pm
Location: DFW, TX, USA
Contact:

Re: Readback - Excluding Text?

#2 Post by jw2pfd »

https://renpy.org/doc/html/history.html
The _history variable can be used to disable and re-enable history storage.

User avatar
Saltome
Veteran
Posts: 244
Joined: Sun Oct 26, 2014 1:07 pm
Deviantart: saltome
Contact:

Re: Readback - Excluding Text?

#3 Post by Saltome »

Wait. What do you mean exclude text from being recorded?
What else do you expect to be recorded?

Are we talking about the rollback feature or is this a different feature..?
And I don't know about you but when I tested this, changing _history didn't do anything.

Anyway, to disable the rollback you use:

Code: Select all

config.rollback_enabled = False
Deviant Art: Image
Discord: saltome
Itch: Phoenix Start

jw2pfd
Regular
Posts: 87
Joined: Tue Sep 18, 2012 9:55 pm
Location: DFW, TX, USA
Contact:

Re: Readback - Excluding Text?

#4 Post by jw2pfd »

Saltome wrote:Are we talking about the rollback feature or is this a different feature..?
And I don't know about you but when I tested this, changing _history didn't do anything.
I may have misunderstood, but I interpreted the question to be about the History tab on the menu and the desire for some things to not be "recorded" there. I hadn't actually messed with it myself before, but changing the _history variable definitely has an effect for me. For example:

Code: Select all

    "line1"
    
    "line2"
    
    $ _history = False
    
    "line3"    
    
    "line4"
       
    $ _history = True
       
    "line5"
        
    "check history"
I expected that "line3" and "line4" would not appear in the history when I opened it up from the menu while on the "check history" dialogue window and that's exactly what I got. (see attached screenshot)
Attachments
screenshot0012.png

User avatar
Saltome
Veteran
Posts: 244
Joined: Sun Oct 26, 2014 1:07 pm
Deviantart: saltome
Contact:

Re: Readback - Excluding Text?

#5 Post by Saltome »

I see, this seems to be new to gui projects.
You'll have to excuse me, I don't use the gui.

I guess he has both answers now anyway.
Deviant Art: Image
Discord: saltome
Itch: Phoenix Start

User avatar
Discostar
Regular
Posts: 40
Joined: Mon Mar 10, 2014 10:29 am
Contact:

Re: Readback - Excluding Text?

#6 Post by Discostar »

Thank you so much for the feedback! You're all understanding the desired effect exactly.
Unfortunately neither of those suggestions worked for me.

I'm using a "readback" feature, I found... somewhere... (I set it up a long time ago, that's why I'm confused about it).

This is what the code looks like:

Code: Select all

# readback.rpy
# drop in readback module for Ren'Py by delta
# this file is licensed under the terms of the WTFPL
# see http://sam.zoy.org/wtfpl/COPYING for details

# voice_replay function added by backansi from Lemma soft forum.
# required renpy 6.12 or higher.
init 5 python:
    style.vscrollbar.xmaximum = 36
    style.vscrollbar.ymaximum = 651
    style.vscrollbar.ypos = 211
    style.vscrollbar.top_bar=Frame("gui/scrollbar.png", 5, 5)
    style.vscrollbar.bottom_bar=Frame("gui/scrollbar.png", 5, 5)
    style.vscrollbar.thumb=Frame("gui/scrollbar_thumb.png", 52, 0)
    
init -3 python:
    # config.game_menu.insert(1,( "text_history", u"Text History", ui.jumps("text_history_screen"), 'not main_menu'))

    # styles
    style.readback_window.xmaximum = 59
    style.readback_window.ymaximum = 203
    style.readback_window.align = (.5, .5)
    style.readback_window.background = "gui/readback_ground.png"
    style.readback_frame.background = None
    style.readback_frame.xpadding = 10
    style.readback_frame.xmargin = 59
    style.readback_frame.ymargin = 203
    
    style.readback_text.color = "#fff"
    style.readback_text.size = 35
    style.readback_text.font = "AlteHaasGroteskRegular.ttf"
    style.readback_label.color = "#ffcc00"
    style.readback_label.align = (0.6, 0)
    #style.readback_text.align = (0.6, 0)
    
    style.create("readback_button", "readback_text")
    style.readback_button.background = None
    
    style.create("readback_button_text", "readback_text")
    style.readback_button_text.selected_color = "#f12"
    style.readback_button_text.hover_color = "#f12"
    
    style.readback_label_text.bold = True
    style.readback_label_text.size = 35
    style.readback_label_text.font = "KGTenThousandReasonsAlt.ttf"
    style.readback_label_text.kerning = 7
    style.readback_label.color = "#fff200"
    # starts adding new config variables
    config.locked = False 
    
    # Configuration Variable for Text History 
    config.readback_buffer_length = 30 # number of lines stored
    config.readback_full = True # True = completely replaces rollback, False = readback accessible from game menu only (dev mode)
    config.readback_disallowed_tags = ["size"] # a list of tags that will be removed in the text history
    config.readback_choice_prefix = ">> "   # this is prefixed to the choices the user makes in readback
    
    # ends adding new config variables
    config.locked = True
    
init -2 python:

    # Two custom characters that store what they said
    class ReadbackADVCharacter(ADVCharacter):
        def do_done(self, who, what):
            store_say(who, what)
            store.current_voice = ''
            return

    class ReadbackNVLCharacter(NVLCharacter):
        def do_done(self, who, what):
            store_say(who, what)
            store.current_voice = ''
            return
            
    # this enables us to show the current line in readback without having to bother the buffer with raw shows
    def say_wrapper(who, what, **kwargs):
        store_current_line(who, what)
        return renpy.show_display_say(who, what, **kwargs)
    
    config.nvl_show_display_say = say_wrapper
    
    adv = ReadbackADVCharacter(show_function=say_wrapper)
    nvl = ReadbackNVLCharacter()
    NVLCharacter = ReadbackNVLCharacter
    
    # rewriting voice function to replay voice files when you clicked dialogues in text history screen
    def voice(file, **kwargs):
        if not config.has_voice:
            return
        
        _voice.play = file
        
        store.current_voice = file

    # overwriting standard menu handler
    # Overwriting menu functions makes Text History log choice which users choose.
    def menu(items, **add_input): 
        
        newitems = []
        for label, val in items:
            if val == None:
                narrator(label, interact=False)
            else:
                newitems.append((label, val))
                
        rv = renpy.display_menu(newitems, **add_input)
        
        # logging menu choice label.
        for label, val in items:
            if rv == val:
                store.current_voice = ''
                store_say(None, config.readback_choice_prefix + label)
        return rv
        
    def nvl_screen_dialogue(): 
        """
         Returns widget_properties and dialogue for the current NVL
         mode screen.
         """

        widget_properties = { }
        dialogue = [ ]
        
        for i, entry in enumerate(nvl_list):
            if not entry:
                continue

            who, what, kwargs = entry

            if i == len(nvl_list) - 1:
                who_id = "who"
                what_id = "what"
                window_id = "window"

            else:
                who_id = "who%d" % i
                what_id = "what%d" % i
                window_id = "window%d" % i
                
            widget_properties[who_id] = kwargs["who_args"]
            widget_properties[what_id] = kwargs["what_args"]
            widget_properties[window_id] = kwargs["window_args"]

            dialogue.append((who, what, who_id, what_id, window_id))
        
        return widget_properties, dialogue
        
    # Overwriting nvl menu function
    def nvl_menu(items):

        renpy.mode('nvl_menu')
        
        if nvl_list is None:
            store.nvl_list = [ ]

        screen = None
        
        if renpy.has_screen("nvl_choice"):
            screen = "nvl_choice"
        elif renpy.has_screen("nvl"):
            screen = "nvl"
            
        if screen is not None:

            widget_properties, dialogue = nvl_screen_dialogue()        

            rv = renpy.display_menu(
                items,
                widget_properties=widget_properties,
                screen=screen,
                scope={ "dialogue" : dialogue },
                window_style=style.nvl_menu_window,
                choice_style=style.nvl_menu_choice,
                choice_chosen_style=style.nvl_menu_choice_chosen,
                choice_button_style=style.nvl_menu_choice_button,
                choice_chosen_button_style=style.nvl_menu_choice_chosen_button,
                type="nvl",                      
                )
                
            for label, val in items:
                if rv == val:
                    store.current_voice = ''
                    store_say(None, config.readback_choice_prefix + label)
            return rv
            
        # Traditional version.
        ui.layer("transient")
        ui.clear()
        ui.close()

        ui.window(style=__s(style.nvl_window))
        ui.vbox(style=__s(style.nvl_vbox))

        for i in nvl_list:
            if not i:
                continue

            who, what, kw = i            
            rv = renpy.show_display_say(who, what, **kw)

        renpy.display_menu(items, interact=False,
                           window_style=__s(style.nvl_menu_window),
                           choice_style=__s(style.nvl_menu_choice),
                           choice_chosen_style=__s(style.nvl_menu_choice_chosen),
                           choice_button_style=__s(style.nvl_menu_choice_button),
                           choice_chosen_button_style=__s(style.nvl_menu_choice_chosen_button),
                           )

        ui.close()

        roll_forward = renpy.roll_forward_info()

        rv = ui.interact(roll_forward=roll_forward)
        renpy.checkpoint(rv)

        for label, val in items:
            if rv == val:
                store.current_voice = ''
                store_say(None, config.readback_choice_prefix + label)
        return rv
        
    ## readback
    readback_buffer = []
    current_line = None
    current_voice = None
    
    def store_say(who, what):
        global readback_buffer, current_voice
        if preparse_say_for_store(what):
            new_line = (preparse_say_for_store(who), preparse_say_for_store(what), current_voice)
            readback_buffer = readback_buffer + [new_line]
            readback_prune()

    def store_current_line(who, what):
        global current_line, current_voice
        current_line = (preparse_say_for_store(who), preparse_say_for_store(what), current_voice)

    # remove text tags from dialogue lines 
    disallowed_tags_regexp = ""
    for tag in config.readback_disallowed_tags:
        if disallowed_tags_regexp != "":
            disallowed_tags_regexp += "|"
        disallowed_tags_regexp += "{"+tag+"=.*?}|{"+tag+"}|{/"+tag+"}"
    
    import re
    remove_tags_expr = re.compile(disallowed_tags_regexp) # remove tags undesirable in readback
    def preparse_say_for_store(input):
        global remove_tags_expr
        if input:
            return re.sub(remove_tags_expr, "", input)

    def readback_prune():
        global readback_buffer
        while len(readback_buffer) > config.readback_buffer_length:
            del readback_buffer[0]

    # keymap overriding to show text_history.
    def readback_catcher():
        ui.add(renpy.Keymap(rollback=(SetVariable("yvalue", 1.0), ShowMenu("text_history"))))
        ui.add(renpy.Keymap(rollforward=ui.returns(None)))

    if config.readback_full:
        config.rollback_enabled = False
        config.overlay_functions.append(readback_catcher)    
    
init python:
    yvalue = 1.0
    class NewAdj(renpy.display.behavior.Adjustment):
        def change(self,value):

            if value > self._range and self._value == self._range:
                return Return()
            else:
                return renpy.display.behavior.Adjustment.change(self, value)
                
    def store_yvalue(y):
        global yvalue
        yvalue = int(y)

screen text_history:

    #use navigation
    tag menu
    
    if not current_line and len(readback_buffer) == 0:
        $ lines_to_show = []
        
    elif current_line and len(readback_buffer) == 0:
        $ lines_to_show = [current_line]
        
    elif current_line and not ( ( len(readback_buffer) == 3 and current_line == readback_buffer[-2]) or current_line == readback_buffer[-1]):  
        $ lines_to_show = readback_buffer + [current_line]
        
    else:
        $ lines_to_show = readback_buffer
    
    
    $ adj = NewAdj(changed = store_yvalue, step = 300)
    
    window:

        hbox align (.23,.1) spacing 20:
            text "TEXT HISTORY" size 40 color "#ffffff" font "KGTenThousandReasonsAlt.ttf" kerning 5 outlines ((1, "fff", 0, 0), (1, "fff", 0, 0)) pos (1, 4)
            
        style_group "readback"
    
        side "c r":
            
            frame:
                
                has viewport:
                    mousewheel True
                    draggable True
                    yinitial yvalue
                    yadjustment adj

                vbox:
                    null height 10
                    
                    for line in lines_to_show:
                        
                        if line[0] and line[0] != " ":
                            label line[0] # name

                        # if there's no voice just log a dialogue
                        if not line[2]:
                            text line[1]
                            
                        # else, dialogue will be saved as a button of which plays voice when clicked
                        else: 
                            textbutton line[1] action Play("voice", line[2] )
                        
                        null height 10
                
            bar adjustment adj style 'vscrollbar'
    hbox:
        imagebutton auto "gui/close01_%s.png" action [Hide("menu"), Return()] xpos 485 ypos 111
#        textbutton _("Return") action Return() align (.97, 28)
I tried $ _readback = False
and $ config.readback_enabled = False
aaannndd $ readback_eneabled = False
aaannndddd $ readback_ = False

Didn't work at all :(
Any ideas?

User avatar
Saltome
Veteran
Posts: 244
Joined: Sun Oct 26, 2014 1:07 pm
Deviantart: saltome
Contact:

Re: Readback - Excluding Text?

#7 Post by Saltome »

You know this is kinda funny.
Looks like this script is so old it even uses the old styling syntax.
It's a wonder it still works.

Doesn't look like there's a built in way to disable the script.
I can hotwire it, but I'd need to know better what you are actually trying to do, and why.

You may want to see how the script behaves if you change this variable to 0 or None or something.
config.readback_buffer_length = 30 # number of lines stored
Deviant Art: Image
Discord: saltome
Itch: Phoenix Start

Post Reply

Who is online

Users browsing this forum: Andredron