Nope, __cfg can be thought of as a WML copy of the unit.So does that mean any changes I make are "stored" immediately? I thought I had to "unstore" the unit (e.g to_map).
It is exactly the same apart from not going into a WML variable.I've always thought of .__cfg as being akin to storing the unit.
Sure you can. AccessBut in WML, I store a unit to a variable, which is then just a WML variable and I can do whatever I want with it (or not). And I suppose I could store it to multiple variables, each independent of the others. Short of doing a by-value copy, I don't think I can do this in lua (this is a rather silly example that can help me understand, not something I can see myself doing).
__cfg
twice and now you have two independent WML copies of the unit.I don't really get your confusion or how you drew any of these conclusions. Every time you accessMy immediate confusion likes with "It'll serialize every time you access it". Seems like that would mean if I made a change the next time I accessed .__cfg my change would be overwritten by the serialized data from the unit. Unless behind the scenes there are actually two copies of the unit, the "real" one and the ".__cfg" one and I'm getting a serialized version of the latter. Then "unstoring" would be syncing the real one from the "working copy".
unit.__cfg
, the game serializes that unit to WML and returns the result. If you access __cfg
twice in a row, you'll end up with two identical but independent WML tables. If you access __cfg
, make some change to the unit directly, and access __cfg
again, the first WML table reflects the state of the unit before the change and the second WML table reflects the state of the unit after the change.There is, and also the first version results in no change to the unit, since you're only modifying the temporary WML table that was created when you accessedAre you saying there is a difference in serialization cost between:andCode:
local unit = wesnoth.units.find_on_map(cfg)[1]unit.__cfg.hitpoints=23unit.__cfg.language_name=_"Uncle Bob"unit.__cfg.experience=100
Code:
local unit = wesnoth.units.find_on_map(cfg)[1].__cfgunit.hitpoints=23unit.language_name=_"Uncle Bob"unit.experience=100
__cfg
. The second version doesn't serialize anything. It directly modifies the unit.Statistics: Posted by Celtic_Minstrel — Today, 5:38 pm