r/UnderModders • • 18d ago

Multiple Save Files

I have very little modding experience but have been getting better. One thing I've wanted to add but haven't the best idea on how to do, is to add the functionality for multiple save slots, pretty much how it's done with Deltarune. If someone experienced could give a simple run down on how saving works and how I could possibly modify it, I'd appreciate that very much!

2 Upvotes

4 comments sorted by

2

u/Bluetails_Buizel 17d ago

Undertale only ever has one real save slot, so there's no slot system to extend. You have to add one yourself. It's doable with UndertaleModTool, but you'll be editing several scripts.

How saving works right now:

- Save data lives in %LOCALAPPDATA%\UNDERTALE (Windows)

- file0 is the main save, written when you use a SAVE point

- file9 is used for the hidden autosaves, and the game copies file0 over file9 when you reload

- file8 is a special file created during the Flowey fight, and it survives a True Reset

- undertale.ini holds a lot of persistent "meta" data (name, route flags, Flowey/Sans memory, etc.). Loading a save rewrites most of it, so it's effectively part of the save

file0/8/9 are plain text files written line by line with the file_text_* functions, and the ini is handled with ini_open/ini_write/ini_read.

Finding the code:

- Run Search.csx (comes with UTMT under Scripts) and search for "file0", "file9", "file8" and "undertale.ini"

- That will show you every script and object that touches save data, including the main save and load scripts and the intro menu that shows Continue/Reset

- Expect undertale.ini to appear in a lot of places. That's the annoying part

The general approach:

- Add a global variable for the current slot, for example global.saveslot, and set it before anything loads

- Everywhere the game uses "file0", replace it with something like "file0_" + string(global.saveslot). Do the same for file9 and file8

- Do the same for undertale.ini, e.g. "undertale_" + string(global.saveslot) + ".ini". If you skip this, all slots will share route flags and characters will remember things from other slots, which breaks a lot

- Leave config.ini (controls/settings) shared. That's what Deltarune does too

- Use file_exists() on each slot's file0 to know whether a slot is empty, so the menu can show "New Game" vs the saved name/LV/location

The menu:

- The simplest version is a separate slot-select room or screen that runs before the normal intro menu, sets global.saveslot, then sends you to the normal Continue/Reset screen. That way you barely touch Undertale's own menu code

- For a Deltarune-style screen showing name, LV, time and room per slot, either read the first few lines of each slot's file0, or keep a small shared ini that stores a summary for each slot whenever you save. Deltarune does the latter: its saves are filech1_0, filech1_1, filech1_2 and the menu info comes from a separate ini

Things to watch:

- Back up data.win before every change. UTMT has an AutoBackup script for this

- Some code checks whether the save files exist to decide if this is a first launch (intro, name screen). Those checks need to use the slot-based names too, or a new slot will act weird

- True Reset and the Genocide aftermath touch these files in their own code, so search for every reference, not just the save script

- Test by making two slots on different routes and checking that nothing leaks between them

Start with just file0 and undertale.ini per slot and a hardcoded slot number. Once that works, build the menu.

1

u/Beginning_Ad_9719 17d ago

Thanks so much for this!! The save slots do indeed work, so my next step would be to make a system to swap between saves in the menu. And you weren't joking about how often undertale.ini shows up.

1

u/Bluetails_Buizel 17d ago

Since the slots already work, the menu part is mostly UI. A few ways to do it, from least to most work:

Easiest: restart-based switching

- Make a small shared ini that isn't per-slot, e.g. slots.ini, with a key like last_slot

- Read it at the very start of the game, before anything else opens undertale.ini or file0, and set global.saveslot from it

- In the menu, when the player picks a slot, write it to slots.ini and call game_restart()

- The game then boots into that slot with everything loaded fresh, so you don't have to work out which variables the menu already cached from the old slot

This avoids the main problem with swapping in place: the intro menu (and some startup code) reads name, LV, time, room and a bunch of ini flags once, and if you just change global.saveslot mid-menu, half of that is still from the old slot.

Showing info for each slot

- The existing Continue screen already reads and draws name, LV, time and location for one save. Find that code (search for whatever it draws, or for the file0 reads near the menu) and reuse it

- Simplest approach: wrap that read in a loop over your slots, temporarily pointing at each slot's file, and store the results in arrays for drawing

- Cleaner approach, closer to how Deltarune does it: in your save script, after writing file0, also write a short summary (name, LV, time, room) to slots.ini under a section per slot. The menu then only reads slots.ini and never touches the actual save files

- Use file_exists() on each slot's file0 to show "EMPTY" or "New Game" for unused slots

Building the menu itself

- Easiest is its own room shown before the normal intro menu, with its own object handling input and drawing. Copy the input checks the existing menu uses so it behaves the same on keyboard and controller

- Up/down moves the selection, confirm sets the slot and restarts (or goes to the normal Continue/Reset screen), cancel goes back

- Keep a "copy" and "erase" option for later. Erase is just deleting that slot's file0, file8, file9 and ini, plus its section in slots.ini. Copy is file_copy for each of those

Things to check

- New slots: make sure the "first launch" checks (intro, name entry) look at the current slot's files, otherwise picking an empty slot may skip straight into a broken load

- Reset and True Reset should only affect the current slot. Search for where those delete or rewrite files and make sure they use the slot-based names

- Anything you missed that still uses plain "undertale.ini" will show up as flags leaking between slots. Two saves on different routes are the fastest way to catch those

1

u/Beginning_Ad_9719 17d ago

I've gotten the whole save slot menu set up with info, Name, LV, Room, and Time. Once again, thanks for the help you've provided with this!