Add Text to save game

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
Yukari
Regular
Posts: 121
Joined: Sun Feb 06, 2011 6:28 am
Completed: Aozora Meikyuu, Yozora Rhapsody, Imolicious, Yume Puzzle, Apprehend;Girlfriend
Projects: Games&Girls, Fuyuzora Rumble
Organization: Yume Creations
Tumblr: yumecreationsvn
Location: Germany
Contact:

Add Text to save game

#1 Post by Yukari » Mon Oct 28, 2013 4:36 pm

Is it possible that the last text in a textbox appear in the savegame? Or that the player can add a comment to the savegame?
Image

User avatar
xavimat
Eileen-Class Veteran
Posts: 1458
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love, unknown
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Contact:

Re: Add Text to save game

#2 Post by xavimat » Mon Oct 28, 2013 4:51 pm

You have the variable save_name ( http://www.renpy.org/doc/html/save_load ... -variables )
With a renpy.input, the user can write the string for the save name.

Code: Select all

$ save_name = renpy.input("Type your save name")
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

Elmiwisa
Veteran
Posts: 476
Joined: Sun Jul 21, 2013 8:08 am
Contact:

Re: Add Text to save game

#3 Post by Elmiwisa » Mon Oct 28, 2013 6:43 pm

Extension on xavimat's suggestion, try using this in the file save/load button:

Code: Select all

action [SetVariable("save_name",_last_say_what),FileAction(i)]

User avatar
Yukari
Regular
Posts: 121
Joined: Sun Feb 06, 2011 6:28 am
Completed: Aozora Meikyuu, Yozora Rhapsody, Imolicious, Yume Puzzle, Apprehend;Girlfriend
Projects: Games&Girls, Fuyuzora Rumble
Organization: Yume Creations
Tumblr: yumecreationsvn
Location: Germany
Contact:

Re: Add Text to save game

#4 Post by Yukari » Tue Oct 29, 2013 3:47 am

@xavimat If I use this the player have to enter the text at the beginning of the game. I want the input only when he save the game.
@Elmiwisa Thank you! Is it also possible to show online the first line? The whole textbox is a bit to much for a single save slot
Image

User avatar
xavimat
Eileen-Class Veteran
Posts: 1458
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love, unknown
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Contact:

Re: Add Text to save game

#5 Post by xavimat » Tue Oct 29, 2013 6:00 pm

Yukari wrote:@xavimat If I use this the player have to enter the text at the beginning of the game. I want the input only when he save the game.
You could do a label with the input code, and have the "Save" button jump to that label.

I'm not able to implement Elmiwisa solution. It works for the save, but not loads the saved games.
For the save, you can use the first 30 characters of the last say this way: _last_say_what[:30]

Code: Select all

action [SetVariable("save_name",_last_say_what[:30]),FileAction(i)]
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

Elmiwisa
Veteran
Posts: 476
Joined: Sun Jul 21, 2013 8:08 am
Contact:

Re: Add Text to save game

#6 Post by Elmiwisa » Tue Oct 29, 2013 7:37 pm

Ah I forgot that the game might be loaded from the main menu, so I did not test that possibility. In this case, I guess a more sophisticated method is needed. Basically, you need to distinguish between the save screen and load screen yourself, rather than relying on FileAction. I also realized another problem with variable substitution.
So here is the fix, which is more sophisticated:
1. Insert this code somewhere:

Code: Select all

init -2 python:
    last_say=""
    class FileLastSaySave(FileSave):
        def __init__(self, name, confirm=True, newest=True, page=None, cycle=False):
            global last_say
            super(FileLastSaySave,self).__init__(name=name,confirm=confirm,newest=newest,page=page,cycle=cycle)
            self.last_say=last_say
        def __call__(self):
            global save_name
            save_name=self.last_say
            return super(FileLastSaySave,self).__call__()
2. Now for the action in the file_picker screen, use this:

Code: Select all

action If(renpy.current_screen().screen_name[0] == "load",FileLoad(i),FileLastSaySave(i))
3. Add this to the beginning of the say screen code:

Code: Select all

    on "show" action SetVariable("last_say",what)
    on "replace" action SetVariable("last_say",what)
xavimat wrote: For the save, you can use the first 30 characters of the last say this way: _last_say_what[:30]

Code: Select all

action [SetVariable("save_name",_last_say_what[:30]),FileAction(i)]
That would cause a different problem though. If text tag was used, it might cut off in the middle of the text tag, and then the game cannot be loaded ever again and will crash every single time you try to open the save/load menu.

However, I am not able to solve this problem. Seems like there are no ways to know how long the text would be. All factors, such as font choice, style choice, ruby text, characters with different size, length of words, language, reading order, etc. will all come in.
A better strategy here would be to redesign the save/load screen, so you don't have text being inside small slot anymore. For example you could have for example a big box that show the current scene and the current dialogue, which will be displayed when you hover the mouse over the slot.
Another additional strategy would be to make sure all the slot are to the extreme right of the screen. Then you can simply make the text box do not line break, and all the extra stuff will simply run off the right side of the screen.

User avatar
xavimat
Eileen-Class Veteran
Posts: 1458
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love, unknown
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Contact:

Re: Add Text to save game

#7 Post by xavimat » Wed Oct 30, 2013 9:49 am

I was wondering... this thread starts with a question about how to do something, but we haven't asked why you want to do this.
I mean, if you want the user to find easily what save refers to some point of the game (I'm making here an assumption), you can use the save_game variable the way usually is used. When every scene/act/part/chapter/arch/sub-part of your game starts, assign a value to that variable:

Code: Select all

$ save_game = "1 - An unexpected encounter"
"I was walking down the street when ..."
...
$ save_game = "2 - Breaking off"
girl "I hate you!"
...
$ save_game = "3 - Reconciliation"
"I decided to apologize..."
But, maybe you want this feature for another reason.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

User avatar
Yukari
Regular
Posts: 121
Joined: Sun Feb 06, 2011 6:28 am
Completed: Aozora Meikyuu, Yozora Rhapsody, Imolicious, Yume Puzzle, Apprehend;Girlfriend
Projects: Games&Girls, Fuyuzora Rumble
Organization: Yume Creations
Tumblr: yumecreationsvn
Location: Germany
Contact:

Re: Add Text to save game

#8 Post by Yukari » Thu Oct 31, 2013 3:57 pm

I just was curious since this function is in a lot japanese VNs.
Example:
Image

If is use

Code: Select all

$ save_game = "This is an example"
and the player has several save slots with this name is harder to get the file.
And for the savegame comment, it's also easier if the player want save on a specific scene and can add a comment like "First date with Mary"
Image

User avatar
saruri
Regular
Posts: 41
Joined: Wed Sep 12, 2012 2:11 am
Contact:

Re: Add Text to save game

#9 Post by saruri » Wed Dec 04, 2013 11:34 am

Hi, I have the same question as Yukari; how to add current dialogue text to Save/Load slot's description? I want it to be like Yukari's screenshot example above, how to do so?

Also, about Elmiwisa's fix above, I can't figure out how/where to add the following code (I'm using imagemap for the save/load screen):

Code: Select all

action If(renpy.current_screen().screen_name[0] == "load",FileLoad(i),FileLastSaySave(i))
Really appreciate if anyone can help me please; I searched online for very long, but still can't find any relevant guide, OTZ......

User avatar
curry nochi rice
Miko-Class Veteran
Posts: 746
Joined: Sat Mar 27, 2010 3:12 am
Projects: Delicatessen, Whom to Notice, Start of Something, Love Sorcery
Organization: Circle Cosine
IRC Nick: Curry
Skype: after.curry.rice
itch: project-rothera
Contact:

Re: Add Text to save game

#10 Post by curry nochi rice » Tue Jul 19, 2016 11:34 am

Necroing this because when you search for "adding text to save renpy" in google, this is the first to come up. My fix is:

Code: Select all

screen save():
    tag menu
    use navigation
    use file_picker("save")

screen load():
    # This ensures that any other menu screen is replaced.
    tag menu
    use navigation
    use file_picker("load")

screen file_picker(currentScreen):
    #on your save-slot/button 
    button:
        if currentScreen == "save":
            action [SetVariable("save_name",_last_say_what[:30]),FileAction(i)]
        else:
            action FileAction(i)
Personal (R-13) | Now at IndieDB | Circle Cosine's itch.io
I wanna be done.

Post Reply

Who is online

Users browsing this forum: Google [Bot], Ocelot