Wesnoth 1.1.2a: augmented variable deletion macros
Moderator: Forum Moderators
Forum rules
- Please use [code] BBCode tags in your posts for embedding WML snippets.
- To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Wesnoth 1.1.2a: augmented variable deletion macros
Upon experimentation, I found that the clear_variable tag in Wesnoth 1.1.2a
* only clears true variables, not key-value pairs. e.g., will clear xfactions.variable but not xfactions
* only does one entry of an array at a time.
The first point is definitely not true for Wesnoth 1.0.2. I haven't tested the second point yet in 1.0.2 (easiest way would be to play HTTT through scenario Crossing, then look at the savefile), but suspect the Wiki is also correct on this for 1.0.2.
So, two macros to assist in getting clean savefiles in Wesnoth 1.1.2a:They respectively remove an entire array, and a key-value pair.
EDIT: looks like this rated a bug report:
https://gna.org/bugs/?func=detailitem&item_id=6148
Fixed in 1.1.7.[/url]
* only clears true variables, not key-value pairs. e.g., will clear xfactions.variable but not xfactions
* only does one entry of an array at a time.
The first point is definitely not true for Wesnoth 1.0.2. I haven't tested the second point yet in 1.0.2 (easiest way would be to play HTTT through scenario Crossing, then look at the savefile), but suspect the Wiki is also correct on this for 1.0.2.
So, two macros to assist in getting clean savefiles in Wesnoth 1.1.2a:
Code: Select all
#define FLUSHARRAY VAR
{VARIABLE_OP random to_variable {VAR}.length}
[while]
[variable]
name=random
greater_than=0
[/variable]
[do]
{CLEAR_VARIABLE {VAR}}
[set_variable]
name=random
add=-1
[/set_variable]
[/do]
[/while]
{CLEAR_VARIABLE random}
#enddef
#define CLEAR_KEY_VALUE VAR
{VARIABLE ({VAR}.variable) {VAR}}
{CLEAR_VARIABLE {VAR}}
#enddef
EDIT: looks like this rated a bug report:
https://gna.org/bugs/?func=detailitem&item_id=6148
Fixed in 1.1.7.[/url]