Adding choices selected to History without showing to user
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.
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.
- wyverngem
- Miko-Class Veteran
- Posts: 615
- 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
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.
I want to be able to change the color of the choice selected font in the history screen.
- wyverngem
- Miko-Class Veteran
- Posts: 615
- 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
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.
class HistoryEntry
_history_list = [ ]
I'm all right with manually adding the choices.
Re: Adding choices selected to History without showing to us
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.
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.
- wyverngem
- Miko-Class Veteran
- Posts: 615
- 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
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
Re: Adding choices selected to History without showing to us
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.
- wyverngem
- Miko-Class Veteran
- Posts: 615
- 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
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.
Re: Adding choices selected to History without showing to us
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
- 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
Old thread, but since there was no code shared for adding history entries for selected choices, here's mine:
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.
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)
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.
- RicharDann
- Veteran
- Posts: 286
- Joined: Thu Aug 31, 2017 11:47 am
- Contact:
Re: Adding choices selected to History without showing to user
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!
This code gave me the clue I needed and thus saved me a great deal of headache.
Thanks a bunch!
The most important step is always the next one.
- 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
Glad to hear it helped!
-
- Regular
- Posts: 82
- Joined: Fri Apr 07, 2017 2:17 pm
- Projects: Imperial Grace (on going), Autumn Spirit, Ballads at Midnight
- Contact:
Re: Adding choices selected to History without showing to user
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 :
and then I used your function, with just a little if to avoid some menu prediction being displayed :
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]
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)
- 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
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.
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3785
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
Re: Adding choices selected to History without showing to user
Ren'Py actually has a python function for doing this, though manual.
Add this after each choice, with the name of the choice or modified text.
Code: Select all
$ narrator.add_history(kind="adv", who=narrator.name, what="Text to appear in history.")
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
Twitter
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
-
- Newbie
- Posts: 8
- Joined: Fri Sep 03, 2021 1:05 pm
- Projects: The Alchemist - VN bara (azephir.itch.io/the-alchemist)
- itch: azephir
- Contact:
Re: Adding choices selected to History without showing to user
Yeah, you can even add it to the screen choice, to not have to script it manually after each option.
Just remplace in the screens.rpy that :
by that :
Hope it'll help you like it helped me.
Cheers
Edit : I know it's kind of necrobump, but it takes me time to found this (with help!), and it could save time to others, so i put it here.
Just remplace in the screens.rpy that :
Code: Select all
screen choice(items):
style_prefix "choice"
vbox:
for i in items:
textbutton i.caption action i.action
by that :
Code: Select all
screen choice(items):
style_prefix "choice"
vbox:
for i in items:
textbutton i.caption action [i.action, Function(narrator.add_history, kind="adv",who=__("Choice:"),what=__(i.caption))]
Cheers
Edit : I know it's kind of necrobump, but it takes me time to found this (with help!), and it could save time to others, so i put it here.
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot]