renpy.save() lag problem

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
Jacksono
Newbie
Posts: 8
Joined: Sat Aug 08, 2020 4:54 am
Contact:

renpy.save() lag problem

#1 Post by Jacksono »

Hi

In my game, I have decided to implement a very simple saving system (rather than the default saving system) so I can easily control when saving can occur and not. This includes after a choice is made and when the player quits the game or returns to the menu.

The code looks like this:

Code: Select all

init python:
	def SAVE_GAME():
        
        	renpy.save("SAVE_FILE")

default allow_save = False # When False, Quitting nor Returning to Menu saves (placed in script of game where appropriate)
Therefore, anytime I want the game to save, I just call SAVE_GAME().

The problem is, when I save, the game lags for a second or so. For example, the file size of the Save file is around 237 kB on average. I noticed an autosave file of the same size does not cause any lag to occur. Why is this the case and is there any solution to prevent lag?

Thank you for any help and I hope I explained the issue well.
-- There is always a happy ending! --

Jacksono
Newbie
Posts: 8
Joined: Sat Aug 08, 2020 4:54 am
Contact:

Re: renpy.save() lag problem

#2 Post by Jacksono »

Such a pityyy
-- There is always a happy ending! --

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: renpy.save() lag problem

#3 Post by Alex »

Why don't just use autosave?

Jacksono
Newbie
Posts: 8
Joined: Sat Aug 08, 2020 4:54 am
Contact:

Re: renpy.save() lag problem

#4 Post by Jacksono »

Alex wrote: Wed Jun 23, 2021 12:28 pm Why don't just use autosave?
Yeah, it would be a quick alternative, but the problem is I desire to switch off saving at certain points in the game for in-game purposes. What I am more interested in is why does using renpy.save() cause a lag, while autosave does not cause a lag (especially considering the file is the same size for either)?

Thank you for responding in any case :)
-- There is always a happy ending! --

User avatar
uyjulian
Regular
Posts: 128
Joined: Sun Mar 08, 2015 1:40 pm
Github: uyjulian
Contact:

Re: renpy.save() lag problem

#5 Post by uyjulian »

The process will need time to save to file, so that is the reason why there is a lag. It will block until the write is finished.
For autosave, this is done on separate thread so there is much less lag on powerful devices.

To force autosave, you can use renpy.loadsave.force_autosave(True)
This will not block, so the game will continue to run while the autosave is in progress.

Jacksono
Newbie
Posts: 8
Joined: Sat Aug 08, 2020 4:54 am
Contact:

Re: renpy.save() lag problem

#6 Post by Jacksono »

uyjulian wrote: Thu Jun 24, 2021 3:13 am The process will need time to save to file, so that is the reason why there is a lag. It will block until the write is finished.
For autosave, this is done on separate thread so there is much less lag on powerful devices.

To force autosave, you can use renpy.loadsave.force_autosave(True)
This will not block, so the game will continue to run while the autosave is in progress.
Ooo I see. Thank you for your explanation. Is there a way (without touching the source Renpy code) that could make the renpy.save() function save on a separate thread as is the case with autosaving?

Otherwise, using renpy.loadsave.force_autosave(True) could definitely be a viable alternative. Thank you for your help. I appreciate it :)
-- There is always a happy ending! --

Post Reply

Who is online

Users browsing this forum: Alex, Andredron, Bing [Bot], geoWaffle