Adding choices selected to History without showing to user

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
wyverngem
Miko-Class Veteran
Posts: 614
Joined: Mon Oct 03, 2011 7:27 pm
Completed: Simple as Snow, Lady Luck's Due,
Projects: Aether Skies, Of the Waterfall
Tumblr: casting-dreams
itch: castingdreams
Location: USA
Contact:

Adding choices selected to History without showing to user

#1 Post by wyverngem » Thu Sep 15, 2016 11:13 am

In the new History is there a way to show what choice the player made in the history without showing it to them on screen?
I want to be able to change the color of the choice selected font in the history screen.

User avatar
wyverngem
Miko-Class Veteran
Posts: 614
Joined: Mon Oct 03, 2011 7:27 pm
Completed: Simple as Snow, Lady Luck's Due,
Projects: Aether Skies, Of the Waterfall
Tumblr: casting-dreams
itch: castingdreams
Location: USA
Contact:

Re: Adding choices selected to History without showing to us

#2 Post by wyverngem » Mon Sep 19, 2016 4:37 pm

So I was reading the documentation and came across this: https://www.renpy.org/doc/html/history. ... storyEntry Still haven't figured how to add the information manually though. I know it has something to do with these:

class HistoryEntry

_history_list = [ ]

I'm all right with manually adding the choices.

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

Re: Adding choices selected to History without showing to us

#3 Post by philat » Wed Sep 21, 2016 9:38 pm

Well, you can just manually add a history entry, I suppose. The old readback code (https://www.renpy.org/wiki/renpy/doc/co ... xt_History ) also hijacked the menu handler to record choices automatically, but I don't think the new history does that.

Simple (if somewhat laborious solution): Look through character.py to to see how a new HistoryEntry is generated by regular dialogue. Adapt as necessary for your choices and invoke that manually in your script.

More complex solution: Hijack the menu handler a la old history code.

Wait and see solution: Bug PyTom about incorporating this in the new history out of the box. ;)

User avatar
wyverngem
Miko-Class Veteran
Posts: 614
Joined: Mon Oct 03, 2011 7:27 pm
Completed: Simple as Snow, Lady Luck's Due,
Projects: Aether Skies, Of the Waterfall
Tumblr: casting-dreams
itch: castingdreams
Location: USA
Contact:

Re: Adding choices selected to History without showing to us

#4 Post by wyverngem » Thu Sep 22, 2016 11:39 am

I can append the _history_list variable, but I don't know how to do it properly to add the new entry in the History Screen. If I create a variable called "userchoice" I don't know what to set it to. When I try HistoryEntry() from the documentation it tells me HistoryEntry is not defined.

Code: Select all

define e = Character('Eileen')

label start:
    "Hello, world." #History enters this as usual.
    
    "[_history_list]" #Displays [<History None u'Hello, world.'>]
    menu:
        "1 line added.":
            $ userchoice = HistoryEntry(kind=adv, who=None, what="1 line added.") #Breaks here. Doesn't work. HistoryEntry not defined.
            $ _history_list.append(userchoice)
            "I write here."
        "2 line added.":
            $ userchoice = "2 line added."
            $ _history_list.append(userchoice) #Appends variable, but not correctly. "who" not defined and "what" not defined when you open history screen. 
            "I read here."
    "[_history_list]"
    
    "game here."

    return

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

Re: Adding choices selected to History without showing to us

#5 Post by philat » Fri Sep 23, 2016 2:16 am

Never really bothered to go too deep under the hood of renpy, but I imagine the issue is that renpy script doesn't have access to character.py directly and therefore doesn't see the HistoryEntry definition. The definition is super bare bones anyway, though, so just throw that into a init python somewhere in your script.

User avatar
wyverngem
Miko-Class Veteran
Posts: 614
Joined: Mon Oct 03, 2011 7:27 pm
Completed: Simple as Snow, Lady Luck's Due,
Projects: Aether Skies, Of the Waterfall
Tumblr: casting-dreams
itch: castingdreams
Location: USA
Contact:

Re: Adding choices selected to History without showing to us

#6 Post by wyverngem » Wed Sep 28, 2016 9:05 pm

I was able to dig into the code a little more and figured out how to add history lines. I will not post it here since I do not know how to troubleshoot it if it breaks the game.

kalesco
Regular
Posts: 25
Joined: Wed Apr 18, 2018 9:34 am
Contact:

Re: Adding choices selected to History without showing to us

#7 Post by kalesco » Thu Apr 26, 2018 6:58 am

wyverngem wrote:
Wed Sep 28, 2016 9:05 pm
I was able to dig into the code a little more and figured out how to add history lines. I will not post it here since I do not know how to troubleshoot it if it breaks the game.
Would you please care to share your code anyway? I'm trying to add choices to the history but had no luck until now. I use the "new" history system. The old readback code had the choices but I can't figure out how to use this properly :-(

User avatar
SleepKirby
Veteran
Posts: 255
Joined: Mon Aug 09, 2010 10:02 pm
Projects: Eastern Starlight Romance, Touhou Mecha
Organization: Dai-Sukima Dan
Location: California, USA
Contact:

Re: Adding choices selected to History without showing to user

#8 Post by SleepKirby » Sat Jun 29, 2019 2:15 am

Old thread, but since there was no code shared for adding history entries for selected choices, here's mine:

Code: Select all

init python:

    def menu(items, **add_input):
        """Overwrites the default menu handler, thus allowing us to log the
        choice made by the player.
        The default menu handler is set to renpy.display_menu(), as seen in
        renpy/defaultstore.py.
        Implementation of this is based on delta's readback module."""
        rv = renpy.display_menu(items, **add_input)
        for item_text, choice_obj in items:
            if rv == choice_obj.value:
                log_menu_choice(item_text)
        return rv

    def log_menu_choice(item_text):
        """Log a choice-menu choice, which is passed in as item_text.
        Implementation based on add_history() in renpy/character.py."""
        h = renpy.character.HistoryEntry()
        h.who = ""
        h.what = ">> " + item_text
        h.what_args = []

        if renpy.game.context().rollback:
            h.rollback_identifier = renpy.game.log.current.identifier
        else:
            h.rollback_identifier = None

        _history_list.append(h)

        while len(_history_list) > renpy.config.history_length:
            _history_list.pop(0)
I hijacked the menu handler like delta's old readback module, since I couldn't think of a better way to do it. It would be cleaner if Ren'Py provided an 'after menu choice' callback where we could put the logic, but there's no such callback that I can find.

log_menu_choice() is the builtin-Ren'Py-history equivalent of delta's store_say(). At least it works as far as I can tell.

I don't know why, but using delta's menu() verbatim (other than replacing the store_say() call with log_menu_choice()) failed to log anything when I tried it (could swear it worked for me before, same Ren'Py version). I had to add '.value' in the third-to-last line for it to work. I went and simplified the function while I was at it, since I couldn't think of why the rest was needed.

Tested with Ren'Py 7.2.2.491.

User avatar
RicharDann
Veteran
Posts: 237
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: Adding choices selected to History without showing to user

#9 Post by RicharDann » Sun Oct 06, 2019 7:47 am

Just wanted to say thank you so much to SleepKirby for sharing your code, I was having a hard time figuring out how to create HistoryEntry objects and update _history_list, the Docs are still not very clear about this.

This code gave me the clue I needed and thus saved me a great deal of headache.

Thanks a bunch!
The most important words a man can say are, “I will do better.”

User avatar
SleepKirby
Veteran
Posts: 255
Joined: Mon Aug 09, 2010 10:02 pm
Projects: Eastern Starlight Romance, Touhou Mecha
Organization: Dai-Sukima Dan
Location: California, USA
Contact:

Re: Adding choices selected to History without showing to user

#10 Post by SleepKirby » Sun Oct 06, 2019 5:51 pm

Glad to hear it helped!

User avatar
Ayael
Regular
Posts: 71
Joined: Fri Apr 07, 2017 2:17 pm
Projects: Anoldor, medieval fantasy otome game.
Contact:

Re: Adding choices selected to History without showing to user

#11 Post by Ayael » Mon Jul 27, 2020 3:32 pm

Old thread again, but this was super useful !!! Still, I was a bit uncomfortable to the idea of overwriting a renpy function, so I used your very useful code to do it a bit differently :

In choice screen I replaced by :

Code: Select all

for i, (caption, action, chosen) in enumerate(items):
        
                button:
                    
                    text caption 
                    action [Function(log_menu_choice, caption), action]
and then I used your function, with just a little if to avoid some menu prediction being displayed :

Code: Select all

def log_menu_choice(item_text):
        if item_text != "Menu Prediction":
            """Log a choice-menu choice, which is passed in as item_text.
            Implementation based on add_history() in renpy/character.py."""
            h = renpy.character.HistoryEntry()
            h.who = ""
            h.what = ">> " + item_text
            h.what_args = []

            if renpy.game.context().rollback:
                h.rollback_identifier = renpy.game.log.current.identifier
            else:
                h.rollback_identifier = None

            _history_list.append(h)

            while len(_history_list) > renpy.config.history_length:
                _history_list.pop(0)

User avatar
SleepKirby
Veteran
Posts: 255
Joined: Mon Aug 09, 2010 10:02 pm
Projects: Eastern Starlight Romance, Touhou Mecha
Organization: Dai-Sukima Dan
Location: California, USA
Contact:

Re: Adding choices selected to History without showing to user

#12 Post by SleepKirby » Mon Jul 27, 2020 7:18 pm

That looks like a nice way of doing it! Yeah, I think customizing a screen seems cleaner than overwriting the menu handler. Thanks for sharing.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3129
Joined: Mon Dec 14, 2015 5:05 am
Location: Your monitor
Contact:

Re: Adding choices selected to History without showing to user

#13 Post by Imperf3kt » Mon Jul 27, 2020 8:12 pm

Ren'Py actually has a python function for doing this, though manual.

Code: Select all

$ narrator.add_history(kind="adv", who=narrator.name, what="Text to appear in history.")
Add this after each choice, with the name of the choice or modified text.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py
Free Android GUI - Updated occasionally

Post Reply

Who is online

Users browsing this forum: Google [Bot], Sergei Falcon