Page 1 of 1

renpy.save() lag problem

Posted: Thu Jun 17, 2021 12:42 am
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.

Re: renpy.save() lag problem

Posted: Wed Jun 23, 2021 6:31 am
by Jacksono
Such a pityyy

Re: renpy.save() lag problem

Posted: Wed Jun 23, 2021 12:28 pm
by Alex
Why don't just use autosave?

Re: renpy.save() lag problem

Posted: Wed Jun 23, 2021 10:50 pm
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 :)

Re: renpy.save() lag problem

Posted: Thu Jun 24, 2021 3:13 am
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.

Re: renpy.save() lag problem

Posted: Thu Jun 24, 2021 8:13 am
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 :)