How to save game into global variable

Discussion of Lua and LuaWML support, development, and ideas.

Moderator: Forum Moderators

Post Reply
User avatar
ZombieKnight
Posts: 248
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

How to save game into global variable

Post by ZombieKnight »

Hi
How should I save game into global variable in a way I can load it using WML/Lua API?
Maybe I could copy/reproduce code for saving and loading regular savefiles?
Thanks (in advance, becouse I may forget to thank later ^^)
I had saurian in profile before, but I've merged my discord profile with forum one...
Working on campaign Bandits from Brown Hills
User avatar
Ravana
Forum Moderator
Posts: 3063
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: How to save game into global variable

Post by Ravana »

You can look into wesnoth.game_events.on_save.
User avatar
Celtic_Minstrel
Developer
Posts: 2273
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: How to save game into global variable

Post by Celtic_Minstrel »

There is probably no way to save the entire game with all the information of a real saved game. You might be able to get close by writing wesnoth.scenario.__cfg (if that exists, didn't check) and also dumping every unit and maybe a few other things.
ZombieKnight wrote: May 3rd, 2024, 7:07 pm Maybe I could copy/reproduce code for saving and loading regular savefiles?
Nope! It's written in C++ and there's no way for you to get at it unless you build a custom version of the game. In principle I guess you could reimplement the whole thing in Lua, but that's only assuming all that data is available to Lua, which is probably not the case. (I'm pretty sure at least stats can't be read from Lua.)
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
ZombieKnight
Posts: 248
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: How to save game into global variable

Post by ZombieKnight »

I thought of a way saving wml table, and then map data...
And that should be enought
I had saurian in profile before, but I've merged my discord profile with forum one...
Working on campaign Bandits from Brown Hills
Post Reply