wesnoth.game_events.on_load/save

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

Moderator: Forum Moderators

Post Reply
Choicerer
Posts: 238
Joined: April 29th, 2017, 11:37 pm

wesnoth.game_events.on_load/save

Post by Choicerer »

I didn't realise global lua variables don't get stored in saves and I based my new version of my add-on around them. Now I'm forced to use on_load and on_save, but there's one weird thing going on.
On load is also fired on game start, so I'm forced to add checks in my variable converting function to find out if the tables being passed are empty (since i'm firing on_load before anything else happens).
On save is fired each side turn, even with max autosaves set to 0.. Effectively then I'm dumping my lua tables to WML every side turn... That's a lot of pointless dumping, sadly... I still don't understand though why this would happen with 0 autosaves and for each side in a local game...
Am I doing something wrong or are those functions supposed to be called like this?
User avatar
Ravana
Forum Moderator
Posts: 2934
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: wesnoth.game_events.on_load/save

Post by Ravana »

From what I understand, it is better to keep state variables in WML. That is using wml.variables.
gfgtdf
Developer
Posts: 1431
Joined: February 10th, 2013, 2:25 pm

Re: wesnoth.game_events.on_load/save

Post by gfgtdf »

the 'max autosaves' probably works by 'step1= create an autosave, step2) delete all save until n remaining' with no special handling of the case when it is set to 0, but i think there is another preference that allows you to turn of autosave complteley.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
gfgtdf
Developer
Posts: 1431
Joined: February 10th, 2013, 2:25 pm

Re: wesnoth.game_events.on_load/save

Post by gfgtdf »

hmm looking at the code it's probably a bug, adding a report on our tracker https://github.com/wesnoth/wesnoth/issues increases the chance that it will be fixed for 1.14.2
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
Choicerer
Posts: 238
Joined: April 29th, 2017, 11:37 pm

Re: wesnoth.game_events.on_load/save

Post by Choicerer »

gfgtdf wrote: May 19th, 2018, 8:56 pm the 'max autosaves' probably works by 'step1= create an autosave, step2) delete all save until n remaining' with no special handling of the case when it is set to 0, but i think there is another preference that allows you to turn of autosave complteley.
Hmmm, I haven't been able to find that option?
gfgtdf wrote: May 19th, 2018, 9:02 pm hmm looking at the code it's probably a bug, adding a report on our tracker https://github.com/wesnoth/wesnoth/issues increases the chance that it will be fixed for 1.14.2
Okay, I might do that then. So the fact that it does it on every local side's turn is a bug as well?
Ravana wrote: May 19th, 2018, 8:47 pm From what I understand, it is better to keep state variables in WML. That is using wml.variables.
Hm, possibly, however:
1 - I have a ton of lua global settings tables now and a ton of functions that use them.
2 - Even if I moved all of them back to WML, I'd still have to be pulling them into LUA every time I use one of the functions, which is quite often.
User avatar
Ravana
Forum Moderator
Posts: 2934
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: wesnoth.game_events.on_load/save

Post by Ravana »

You can load the settings during preload into lua variables, and only write to wml.variables when you need to save something.
Choicerer
Posts: 238
Joined: April 29th, 2017, 11:37 pm

Re: wesnoth.game_events.on_load/save

Post by Choicerer »

That's pretty much what I'm doing (the modification options settings can only be saved in WML), except I declare my data that isn't dependent on those options in LUA. I'd still be writing to wml though. But yes, for the static data that would work better.
Only I'm not really going to rewrite my code now, this works anyway.
gfgtdf
Developer
Posts: 1431
Joined: February 10th, 2013, 2:25 pm

Re: wesnoth.game_events.on_load/save

Post by gfgtdf »

Choicerer wrote: May 19th, 2018, 9:16 pm Hmmm, I haven't been able to find that option?
Hmm right i just looked it up and it a commandmode option ":no_autosaves" or somthign liek that
Choicerer wrote: May 19th, 2018, 9:16 pm Okay, I might do that then. So the fact that it does it on every local side's turn is a bug as well?
Ye if a lengthly uneeded computation is done, then that is something that it worth fixing, it clearly wouldn't be a top priority issue but on the other hand it's probably not that hard to fix either
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
Choicerer
Posts: 238
Joined: April 29th, 2017, 11:37 pm

Re: wesnoth.game_events.on_load/save

Post by Choicerer »

Well, I'm thinking now I'd simply intialise the global variables in the on_load event instead of prestart, but would that be safe? Well, those that don't depend on the number of sides or any coordinates in the game, at least.
^
Edit - Well, it appears it is and I guess it's still less hassle to recalculate some data on reload rather than pass it around every side turn.

Also, the fact that on_load is being called on game start, is that a bug that is going to be fixed in the future or is it intended?
gfgtdf
Developer
Posts: 1431
Joined: February 10th, 2013, 2:25 pm

Re: wesnoth.game_events.on_load/save

Post by gfgtdf »

Choicerer wrote: May 20th, 2018, 9:30 am Well, I'm thinking now I'd simply intialise the global variables in the on_load event instead of prestart, but would that be safe? Well, those that don't depend on the number of sides or any coordinates in the game, at least.
Hmm yes 'static' datza that does not change during the game can be initilized during on_load or ven eariler (i usualyl initiilaize them during the [lua] when i intililise my functions aswell), see for exampel the code for the scenario 2p dark forcast survival (https://github.com/wesnoth/wesnoth/blob ... recast.lua) it inilizes the fixed span data right on top of that file.
Choicerer wrote: May 20th, 2018, 9:30 am Also, the fact that on_load is being called on game start, is that a bug that is going to be fixed in the future or is it intended?
No this is intended, in fact some addons might rely on that.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
Choicerer
Posts: 238
Joined: April 29th, 2017, 11:37 pm

Re: wesnoth.game_events.on_load/save

Post by Choicerer »

I see. Thanks for the help, guys!
User avatar
Celtic_Minstrel
Developer
Posts: 2158
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: wesnoth.game_events.on_load/save

Post by Celtic_Minstrel »

Instead of on_load and on_save, you should consider using wesnoth.persistent_tags which does the same thing but should be easier to use. See here for documentation and an example.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Choicerer
Posts: 238
Joined: April 29th, 2017, 11:37 pm

Re: wesnoth.game_events.on_load/save

Post by Choicerer »

Thanks, but it's already implemented.
Post Reply