wesnoth.game_events.on_load/save
Moderator: Forum Moderators
wesnoth.game_events.on_load/save
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?
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?
Re: wesnoth.game_events.on_load/save
From what I understand, it is better to keep state variables in WML. That is using wml.variables.
Re: wesnoth.game_events.on_load/save
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.
Re: wesnoth.game_events.on_load/save
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.
Re: wesnoth.game_events.on_load/save
Hmmm, I haven't been able to find that option?
Okay, I might do that then. So the fact that it does it on every local side's turn is a bug as well?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
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.
Re: wesnoth.game_events.on_load/save
You can load the settings during preload into lua variables, and only write to wml.variables when you need to save something.
Re: wesnoth.game_events.on_load/save
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.
Only I'm not really going to rewrite my code now, this works anyway.
Re: wesnoth.game_events.on_load/save
Hmm right i just looked it up and it a commandmode option ":no_autosaves" or somthign liek that
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.
Re: wesnoth.game_events.on_load/save
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?
^
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?
Re: wesnoth.game_events.on_load/save
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.
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.
Re: wesnoth.game_events.on_load/save
I see. Thanks for the help, guys!
- Celtic_Minstrel
- Developer
- Posts: 2290
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: wesnoth.game_events.on_load/save
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.Re: wesnoth.game_events.on_load/save
Thanks, but it's already implemented.