Creating/Loading .SAV files in LunaLua

Post here for help and support regarding LunaLua and SMBX2's libraries and features.

Moderator: Userbase Moderators

ByTheBookGames
Fighter Fly
Fighter Fly
Posts: 36
Joined: Tue Jun 04, 2019 8:35 pm

Creating/Loading .SAV files in LunaLua

Postby ByTheBookGames » Tue Oct 08, 2019 10:05 am

I've been trying to figure out a way to create and load save slots through LunaLua code. Let me clarify what I know/have tried:
  • I know that savestate.lua can be used for storing and loading the current state of a level etc., but I'm looking to access save files themselves if possible.
  • I know the the launcher.js code accesses, creates, and loads save files, but I don't know how to recreate this sort of thing outside the launcher itself. I've tried looking at lunajson encoding/decoding, but I don't know how to use this to create and load save slots in a lunalua code.
  • I know that Misc.saveGame() saves to the current save slot, but I don't know how to change which save slot is active via lunalua, which is my main concern.
I should also clarify that I'm using the basic SMBX2.0 build, not any sort of PAL beta build. My goal in all this is to be able to make a custom intro menu for starting the game where you can create new games, load games, and delete games without the limitations of the clunky 3-slot system. This is the last piece of the puzzle that I haven't been able to figure out. Any help is greatly appreciated.

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9891
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Creating/Loading .SAV files in LunaLua

Postby Emral » Tue Oct 08, 2019 11:17 am

Even if it was possible to switch save slots, it would have nothing to do with loading sav files. Smbx internally has logic for interpreting save data, so it's a matter of calling that function with a specific slot id. That said, I don't know how to do that and recommend just using the launcher. Else users have to select a save slot twice and stuff.

ByTheBookGames
Fighter Fly
Fighter Fly
Posts: 36
Joined: Tue Jun 04, 2019 8:35 pm

Re: Creating/Loading .SAV files in LunaLua

Postby ByTheBookGames » Tue Oct 08, 2019 11:45 am

Enjl,

I really appreciate your quick response. I've actually adjusted the code on the launcher so that it immediately jumps into the game at the starting menu, so that's not really an issue. I'm developing a way to create, save, and load any numbered slot, even beyond 3, from an in-game menu.

Have to admit I'm a bit confused about the distinction you're making between interpreting save data from slot id numbers and loading sav files. I'm familiar with the logic for storing and loading custom data to worlds, global files, etc., using data scripts, but that's not really what I'm after... or at least I don't think it is? Don't save slots read the information in .sav files when they load an episode? Are you saying there is an alternative or better way for saving all the information that a sav file would normally store, and to work on that instead of messing with the .sav files themselves? Is there a way to save things like current level progress in an episode, which specific stars have been acquired, etc., in data files?

Hoeloe
Phanto
Phanto
Posts: 1465
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Creating/Loading .SAV files in LunaLua

Postby Hoeloe » Tue Oct 08, 2019 12:10 pm

The current save slot is stored in memory, and that can be read out and modified, yes (the function Misc.inEditor uses it, since the editor uses save slot 0). Similarly, it is possible to just load and manually parse the .sav file if you want to do that, but I would strongly suggest against trying. LunaLua has systems for saving extra data automatically, and you'd be better off just not using the built-in .sav file data at all and using data you store yourself.

I would also VERY strongly recommend against modifying the launcher (unless you just mean modifying the code for your episode's launcher page).

ByTheBookGames
Fighter Fly
Fighter Fly
Posts: 36
Joined: Tue Jun 04, 2019 8:35 pm

Re: Creating/Loading .SAV files in LunaLua

Postby ByTheBookGames » Tue Oct 08, 2019 1:23 pm

Hoeloe,

Thanks for your reply. Could you point me to the mem address that reads/modifies the current save slot? Having trouble finding Misc.inEditor as well. Thanks for your help.

Hoeloe
Phanto
Phanto
Posts: 1465
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Creating/Loading .SAV files in LunaLua

Postby Hoeloe » Tue Oct 08, 2019 3:49 pm

It's 0x00B2C62A, and it's a FIELD_WORD address. This does just change the internal save slot, and won't do any file loading if you change it. I also have no idea how it'll react to being changed mid-game, nor how it'll react to values larger than 3.

ByTheBookGames
Fighter Fly
Fighter Fly
Posts: 36
Joined: Tue Jun 04, 2019 8:35 pm

Re: Creating/Loading .SAV files in LunaLua

Postby ByTheBookGames » Tue Oct 08, 2019 9:01 pm

This is perfect, thank you. Surprisingly, values larger than 3 work just fine. Changing the 0x00B2C62A address right before using Misc.loadEpisode works perfectly for changing to a specified world and save slot (even if it's a new save slot or past 3).

My remaining problem is that this bugs out when running on the editor---the way that I have things set up, at least. This should be easily solvable if there's a mem address for detecting whether you're using the level editor tester or not. I've tried using 0x00B25134 and 0x00B250B4 but those didn't sense when I was using the editor. Is there another mem address that I'm missing?

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9891
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Creating/Loading .SAV files in LunaLua

Postby Emral » Wed Oct 09, 2019 1:04 am

You can use Misc.inEditor() to check whether you're in the editor (see classexpander.lua for the definition), and do not prompt save slot selection if you are in the editor, as many editor-specific functions rely on the save slot 0.

ByTheBookGames
Fighter Fly
Fighter Fly
Posts: 36
Joined: Tue Jun 04, 2019 8:35 pm

Re: Creating/Loading .SAV files in LunaLua

Postby ByTheBookGames » Thu Oct 17, 2019 11:51 am

Enjl wrote:
Wed Oct 09, 2019 1:04 am
You can use Misc.inEditor() to check whether you're in the editor (see classexpander.lua for the definition), and do not prompt save slot selection if you are in the editor, as many editor-specific functions rely on the save slot 0.
Thanks! When I realized Misc.inEditor() is shorthand for reading save slot 0, I found out that my problem was that I had set up the launcher to jump straight into SMBX without loading a save slot, so the intro menu running normally was also save slot 0 until I loaded an episode. This made it so I had no way of distinguishing editor mode from normal mode in Lua. Once I changed the launcher script to load a save slot before running, it all worked perfectly.

Anyway, I got what I was looking for thanks to you both, so thank you


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 38 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari