[SOLVED] Add selected choice to History?

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
lking22
Regular
Posts: 50
Joined: Sun Dec 03, 2017 3:33 am
Projects: Grey Feather
itch: freefall-games
Contact:

[SOLVED] Add selected choice to History?

#1 Post by lking22 »

What I would like to do is automatically add the selected choice to the history screen. Most of the editing has actually been done in the choice screen. So, I've gotten halfway there, I think.

Code: Select all

screen choice(items):
    style_prefix "choice"
    vbox:
        for i in items:
            textbutton i.caption action [narrator.add_history(kind="adv", who="{b}>>>{/b}", what=i.caption), i.action]
The problem is, this adds ALL choices to the history screen. For example the history screen will show:
Narrator: Would you like to show trigger warnings?
>>> Yes
>>> No
I would like for it to only show the selected choice, not all choices.

---

If I just put 'i' instead of 'i.caption' then it throws up this error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/screens.rpy", line 679, in execute
    screen history():
  File "game/screens.rpy", line 679, in execute
    screen history():
  File "game/screens.rpy", line 686, in execute
    use game_menu(_("History"), scroll=("vpgrid" if gui.history_height else "viewport"), yinitial=1.0):
  File "game/screens.rpy", line 325, in execute
    screen game_menu(title, scroll=None, yinitial=0.0):
  File "game/screens.rpy", line 325, in execute
    screen game_menu(title, scroll=None, yinitial=0.0):
  File "game/screens.rpy", line 333, in execute
    frame:
  File "game/screens.rpy", line 335, in execute
    hbox:
  File "game/screens.rpy", line 336, in execute
    frame:
  File "game/screens.rpy", line 338, in execute
    if scroll == "viewport":
  File "game/screens.rpy", line 339, in execute
    viewport:
  File "game/screens.rpy", line 346, in execute
    vbox:
  File "game/screens.rpy", line 347, in execute
    transclude
  File "game/screens.rpy", line 686, in execute
    use game_menu(_("History"), scroll=("vpgrid" if gui.history_height else "viewport"), yinitial=1.0):
  File "game/screens.rpy", line 690, in execute
    for h in _history_list:
  File "game/screens.rpy", line 692, in execute
    window:
  File "game/screens.rpy", line 695, in execute
    has fixed:
  File "game/screens.rpy", line 710, in execute
    text what:
Exception: Cannot display (u'Yes', <renpy.ui.ChoiceReturn object at 0x0393A290>, True) as text.
That seems to be saying that version of the code is pulling up the one option that the player selects, but it grabs the full code for that selection, not just the caption. So basically I can get halfway to what I want in two different ways, but I can't seem to bring it all together.
Last edited by lking22 on Wed Jan 22, 2020 12:40 pm, edited 1 time in total.
Releases:
Image

Current projects:
In the Ashes of Dawn
Split Psyche
Savestate Gambit

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

Re: Add selected choice to History?

#2 Post by Imperf3kt »

I've been considering this, but never gotten around to it.

What I had in mind, was simply to add to each option, some invisible dialogue that automatically advances to the next dialogue block after 0.01 seconds.

The player will never see the text but it should appear in the history just fine.
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

User avatar
lking22
Regular
Posts: 50
Joined: Sun Dec 03, 2017 3:33 am
Projects: Grey Feather
itch: freefall-games
Contact:

Re: Add selected choice to History?

#3 Post by lking22 »

Yeah, it's possible to do it manually by adding this code after each choice:

Code: Select all

$ narrator.add_history(kind="adv", who=narrator.name, what="YourChoice")
#Note: You can replace narrator.name with the name you want displayed beside the choice.
But I'm making a fairly big game with a lot of choices and I would prefer if I didn't have to remember to do it manually every time.
Releases:
Image

Current projects:
In the Ashes of Dawn
Split Psyche
Savestate Gambit

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Add selected choice to History?

#4 Post by Remix »

Try:

Code: Select all

action [Function(narrator.add_history, kind="adv", who="{b}>>>{/b}", what=i.caption), i.action]
Without using the Function() screen action, the add_history would run under prediction and appear for all choices
Frameworks & Scriptlets:

User avatar
lking22
Regular
Posts: 50
Joined: Sun Dec 03, 2017 3:33 am
Projects: Grey Feather
itch: freefall-games
Contact:

Re: Add selected choice to History?

#5 Post by lking22 »

Oh my goodness, it worked like a charm! Thank you so much!
Releases:
Image

Current projects:
In the Ashes of Dawn
Split Psyche
Savestate Gambit

Post Reply

Who is online

Users browsing this forum: Bing [Bot]