Follow-up Comment #2, bug #23345 (project wesnoth):

There is a lot of confusion around preload events.

The purpose of preload events right now is to work around a short-coming of
lua, which is that the lua state is not persistent. That is, when the user
saves the game and reloads it, all the lua variables will be cleared, all of
the lua helper functions the user may have defined will be cleared, and if
they are using any libraries they will have to reload them.

You *could* make it so that whenever lua is used in a scenario, every lua
[event] block will each reload all of the lua libs just before it runs. But
this is (slightly) wasteful and (very) ugly.

There is *no way* in default lua to save the lua state to file. There are
extensions of lua that permit this but we don't have them right now.

Instead, preload events were added. Preload events are not like other events.
They are fired exactly once for each game session just before you load. The
idea is that you put your lua library initializations here.

Preload events are generally *not useful* for WML. For instance, if you make a
preload event that increments a WML variable, the variable will always count
the number of times the game has been reloaded iirc. No other event is
supposed to behave like this -- in general, when you save the game, the game
state is supposed to be exactly the same when you reload it. The event won't
create OOS, but if you want to make scenarios that are not "repeatable", i.e.
they behave differently if you reload them in the middle, I think you could
use preload events to do this.

The only way we could get rid of preload events is if we make lua state
persistent across saves.

1.) I'm not sure if that's actually a very good idea, it would add a fair
amount of complexity and require big changes to our lua core. (I kind of want
to make those changes anyways though.)
2.) The lib that I know that permits to serialize a lua state, may or may not
actually produce a "human readable" string. Wesnoth save files right now are
basically human readable. If they all had to have a block at the end like
[lua] 0x234239849843ab234873274872384 [/lua] I'm not sure if I would actually
like that.
3.) Even if the lua states did get serialized properly, I'm still not sure if
its a good idea to get rid of preload events, if only for backwards
compatibility.

    _______________________________________________________

Reply to this item at:

  <http://gna.org/bugs/?23345>

_______________________________________________
  Message sent via/by Gna!
  http://gna.org/


_______________________________________________
Wesnoth-bugs mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-bugs

Reply via email to