Some questions about saving 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
Parkey
Regular
Posts: 69
Joined: Thu Feb 02, 2012 11:52 am
Contact:

Some questions about saving game

#1 Post by Parkey »

Hello all!

I've been trying to solve this for several days but I have not been able to, so I ask them around here to see if anyone could help me:

1. How to allow changing the name of the saved games or request a text to be entered. In Ren'Py it is now allowed to modify the name of the page, but I would like to be able to request the user to enter a text and save it with that text, instead of with the date (or both).

2. How to delete the saved items. When a slot is pressed, the game is saved or overwritten and I would like to add a button in each slot to eliminate a game already saved.

3. How to copy the text of the screens. I'm creating a game that at certain moments opens a window (pop-up, like the question of overwriting game) and can show from codes to phrases. Some of them are a bit long and it is boring to have to write them, so I was wondering if there is any way that the text that is displayed can be copied to the clipboard or selected with the mouse and copied.

4. How to change the hotkeys to replace them with buttons. For example, to include a button to make a screenshot, instead of pressing "S".

5. And one last question (this one I have not tried yet), is it possible to use other types of python libraries, such as matplotlib?


Thank you very much! :)

rames44
Veteran
Posts: 233
Joined: Sun May 29, 2016 4:38 pm
Contact:

Re: Some questions about saving game

#2 Post by rames44 »

A few answers:

1. I don't have code handy for this right now, but possibly one of the other gurus here can provide it.

2. Users can already delete saves by hovering over the save with the mouse (or getting there with the arrow keys) and pressing the "Delete" key. However, if you wanted to add a button, the appropriate action is FileDelete https://www.renpy.org/doc/html/screen_a ... FileDelete

3. Ren'py doesn't display text as text - it draws the text (i.e. to pixels on the screen). So I don't think there's any way you can do this.

4. If you want to eliminate a hot key from functioning, you can edit the keymap. https://www.renpy.org/doc/html/keymap.html To create a button with the same functionality, you just need to figure out the correct action to trigger. Possibly https://www.renpy.org/doc/html/screen_a ... Screenshot

5. Yes, you can include other Python libraries in your project. You'll have to "import" them into your Ren'py in order to reference them.

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

Re: Some questions about saving game

#3 Post by Imperf3kt »

#3 can be done using the keywords file found in the Ren'Py tutorial.

I'm unable to give you instruction at the moment though.

Note that this method doesn't work on mobile platforms.
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

Parkey
Regular
Posts: 69
Joined: Thu Feb 02, 2012 11:52 am
Contact:

Re: Some questions about saving game

#4 Post by Parkey »

Hey there!

Thanks for the answers!

I've been working a bit to find solutions to that.

1) I started from the screen file_slots and thought about the button code to change the file page name. I've added the following code, but it still gives me an error that I cannot solve.

The first one allows me to write text in the slot, but it does not stay saved like the one in the file page name:

Code: Select all


                        button:
                            style "gui_label_text"
                            add Input(hover_color="#3399ff", size=12, color="#000", adjust_spacing=True, default="", changed=name_func, length=50)
                            key_events True
                            xalign 0.0

The second one gives me the following error when I click the save/load button:

Code: Select all

                        button:
                            style "gui_label_text"
##                            xmaximum 25
##                            ymaximum 15
                            add Input(hover_color="#3399ff", size=12, color="#000", adjust_spacing=True, default="", changed=name_func, length=50)
                            key_events True
                            xalign 0.0
                            ##action name_slot.Toggle()

                            input:
                                style "page_label_text"
                                value VariableInputValue(name_slot, default=True, returnable=True)
The error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/screens.rpy", line 666, in execute
    screen load():
  File "game/screens.rpy", line 666, in execute
    screen load():
  File "game/screens.rpy", line 670, in execute
    use file_slots(_("Cargar"))
  File "game/screens.rpy", line 673, in execute
    screen file_slots(title):
  File "game/screens.rpy", line 673, in execute
    screen file_slots(title):
  File "game/screens.rpy", line 678, in execute
    use game_menu(title):
  File "game/screens.rpy", line 464, in execute
    screen game_menu(title, scroll=None, yinitial=0.0):
  File "game/screens.rpy", line 464, in execute
    screen game_menu(title, scroll=None, yinitial=0.0):
  File "game/screens.rpy", line 473, in execute
    frame:
  File "game/screens.rpy", line 476, in execute
    hbox:
  File "game/screens.rpy", line 482, in execute
    frame:
  File "game/screens.rpy", line 485, in execute
    if scroll == "viewport":
  File "game/screens.rpy", line 516, in execute
    transclude
  File "game/screens.rpy", line 678, in execute
    use game_menu(title):
  File "game/screens.rpy", line 680, in execute
    fixed:
  File "game/screens.rpy", line 700, in execute
    grid gui.file_slot_cols gui.file_slot_rows:
  File "game/screens.rpy", line 708, in execute
    for i in range(gui.file_slot_cols * gui.file_slot_rows):
  File "game/screens.rpy", line 712, in execute
    button:
  File "game/screens.rpy", line 715, in execute
    has vbox
  File "game/screens.rpy", line 728, in execute
    button:
  File "game/screens.rpy", line 737, in execute
    input:
  File "renpy/common/00inputvalues.rpy", line 145, in get_text
    return globals()[self.variable]
KeyError: u'a'

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "renpy/common/_layout/screen_main_menu.rpym", line 28, in script
    python hide:
  File "C:\Users\Aaron\Desktop\renpy-7.0.0-sdk\renpy\ast.py", line 862, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\Users\Aaron\Desktop\renpy-7.0.0-sdk\renpy\python.py", line 1912, in py_exec_bytecode
    exec bytecode in globals, locals
  File "renpy/common/_layout/screen_main_menu.rpym", line 28, in <module>
    python hide:
  File "renpy/common/_layout/screen_main_menu.rpym", line 35, in _execute_python_hide
    ui.interact()
  File "C:\Users\Aaron\Desktop\renpy-7.0.0-sdk\renpy\ui.py", line 287, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "C:\Users\Aaron\Desktop\renpy-7.0.0-sdk\renpy\display\core.py", line 2649, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
  File "C:\Users\Aaron\Desktop\renpy-7.0.0-sdk\renpy\display\core.py", line 3033, in interact_core
    root_widget.visit_all(lambda i : i.per_interact())
  File "C:\Users\Aaron\Desktop\renpy-7.0.0-sdk\renpy\display\core.py", line 511, in visit_all
    d.visit_all(callback)
  File "C:\Users\Aaron\Desktop\renpy-7.0.0-sdk\renpy\display\core.py", line 511, in visit_all
    d.visit_all(callback)
  File "C:\Users\Aaron\Desktop\renpy-7.0.0-sdk\renpy\display\core.py", line 511, in visit_all
    d.visit_all(callback)
  File "C:\Users\Aaron\Desktop\renpy-7.0.0-sdk\renpy\display\core.py", line 511, in visit_all
    d.visit_all(callback)
  File "C:\Users\Aaron\Desktop\renpy-7.0.0-sdk\renpy\display\screen.py", line 424, in visit_all
    callback(self)
  File "C:\Users\Aaron\Desktop\renpy-7.0.0-sdk\renpy\display\core.py", line 3033, in <lambda>
    root_widget.visit_all(lambda i : i.per_interact())
  File "C:\Users\Aaron\Desktop\renpy-7.0.0-sdk\renpy\display\screen.py", line 434, in per_interact
    self.update()
  File "C:\Users\Aaron\Desktop\renpy-7.0.0-sdk\renpy\display\screen.py", line 619, in update
    self.screen.function(**self.scope)
  File "game/screens.rpy", line 666, in execute
    screen load():
  File "game/screens.rpy", line 666, in execute
    screen load():
  File "game/screens.rpy", line 670, in execute
    use file_slots(_("Cargar"))
  File "game/screens.rpy", line 673, in execute
    screen file_slots(title):
  File "game/screens.rpy", line 673, in execute
    screen file_slots(title):
  File "game/screens.rpy", line 678, in execute
    use game_menu(title):
  File "game/screens.rpy", line 464, in execute
    screen game_menu(title, scroll=None, yinitial=0.0):
  File "game/screens.rpy", line 464, in execute
    screen game_menu(title, scroll=None, yinitial=0.0):
  File "game/screens.rpy", line 473, in execute
    frame:
  File "game/screens.rpy", line 476, in execute
    hbox:
  File "game/screens.rpy", line 482, in execute
    frame:
  File "game/screens.rpy", line 485, in execute
    if scroll == "viewport":
  File "game/screens.rpy", line 516, in execute
    transclude
  File "game/screens.rpy", line 678, in execute
    use game_menu(title):
  File "game/screens.rpy", line 680, in execute
    fixed:
  File "game/screens.rpy", line 700, in execute
    grid gui.file_slot_cols gui.file_slot_rows:
  File "game/screens.rpy", line 708, in execute
    for i in range(gui.file_slot_cols * gui.file_slot_rows):
  File "game/screens.rpy", line 712, in execute
    button:
  File "game/screens.rpy", line 715, in execute
    has vbox
  File "game/screens.rpy", line 728, in execute
    button:
  File "game/screens.rpy", line 737, in execute
    input:
  File "C:\Users\Aaron\Desktop\renpy-7.0.0-sdk\renpy\display\behavior.py", line 1094, in __init__
    default = value.get_text()
  File "renpy/common/00inputvalues.rpy", line 145, in get_text
    return globals()[self.variable]
KeyError: u'a'

Windows-8-6.2.9200
Ren'Py 7.0.0.196
AROA 1.0
Thu Aug 23 21:06:47 2018
Any idea?


2) I've write the following code and it works good:

Code: Select all


                        if FileTime(slot, format=_("{#file_time}%A, %B %d %Y, %H:%M"), empty=_("empty")) <> "empty":
                            imagebutton:
                                idle "gui/icon_delete.png" hover "gui/icon_delete_hover.png" action FileDelete(slot)
                                xalign 1.0 ypos 1.0 xoffset 35


3) I've tried to find a way to copy the text, but I couldn't... However, I've put an imagebutton that copy to the clipboard the text in a variable so, when a screen shows that codes or phrases, I assign that string to the variable and the user can copy it.

Code: Select all

init python:
    import pygame.scrap

    def copytext(t):
        pygame.scrap.put(pygame.scrap.SCRAP_TEXT, t.encode("utf-8"))
        if pygame.scrap.contains(pygame.scrap.SCRAP_TEXT):
            renpy.notify("Se ha copiado el texto en el portapapeles.")

    def name_func(newstring):
        store.name_slot = newstring

screen pop:
[...]
	hbox xsize 200 xpos 1.0 xoffset -200 yalign 0.0 yoffset 10:
		imagebutton idle "gui/icon_clipboard.png" hover "gui/icon_clipboard_hover.png" action Function(copytext, t=txt)
[...]
4) I've decided no to do this.

5) Thank you for the answer rames44.

User avatar
MaydohMaydoh
Regular
Posts: 165
Joined: Mon Jul 09, 2018 5:49 am
Projects: Fuwa Fuwa Panic
Tumblr: maydohmaydoh
Location: The Satellite of Love
Contact:

Re: Some questions about saving game

#5 Post by MaydohMaydoh »

1. In your second example, for the input value, name_slot needs to be given as a string, like "name_slot"
3. Instead of using an imagebutton, you could use a textbutton and style it to look like normal text and when the user clicks it, it copies it.

Code: Select all

textbutton txt action Function(copytext, t=txt)

Parkey
Regular
Posts: 69
Joined: Thu Feb 02, 2012 11:52 am
Contact:

Re: Some questions about saving game

#6 Post by Parkey »

Thanks for your answers MaydohMaydoh!

But, for the 1) it still doesn't save the name. It must be some way to save the slot with another name...

Any idea?

User avatar
skyeworks
Regular
Posts: 84
Joined: Thu Jul 27, 2017 11:36 am
Projects: K9-11
itch: skyefrost
Contact:

Re: Some questions about saving game

#7 Post by skyeworks »

I found this link here:

viewtopic.php?t=23749

This probably would help with the user gets to name the save files.
Image

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]