From The Battle for Wesnoth Wiki

Kernigh wrote:

Since Wesnoth 1.1.5, all simple substitution was eliminated in favor of complex substitution, which is more versatile.

There is no source for this claim, and my tests contradict it: In wesnoth 1.2.5, the WML snippet

			{VARIABLE foo_bar 42}
			{VARIABLE b bar}

does nothing, but

			{VARIABLE foo_bar 42}
			{VARIABLE b bar}
			{VARIABLE_OP temp format $foo_$b}

adds 42 gold to side 1. I have therefore reverted the edit. Please only change the content of this page if you are sure you are right.

Meriton 15:25, 15 July 2007 (CEST)

In the source file wesnoth-1.2.5/changelog, under the section for "Wesnoth 1.1.5", it states, "all [event] tags shall perform complex substitution".
Further, the following example passes wesnoth 1.2.5, and at least demonstrates that the [allow_recruit]type= key permits complex substitution:
			# works in 1.2.5
				{VARIABLE title "Sharpshooter"}
				{VARIABLE name title}
					type="Elvish $$name||"
When I made a copy of 2p - Blitz with this event, side 1 was able to recruit Elvish Sharpshooters.
To show why your test failed, I suggest that "$foo_$b" is not a valid complex suggestion. (I do not know why "$foo_$b" does not work; maybe there is a bug in 1.2.5, or I misunderstand how complex substitution works.)
But if this is not a valid expression, how can it be correctly interpreted by [set_variable]format=, which after all does complex substitution, too? Meriton 22:17, 15 July 2007 (CEST)
The wiki page claims that [message]message= allows complex substitution, so I extended your example to be:
			{VARIABLE foo_bar 42}
			{VARIABLE b bar}
				# broken in 1.2.5

				# broken in 1.2.5
When I tested this, side 2 failed to gain 42 gold, and the message box can up with an empty message! --Kernigh 16:35, 15 July 2007 (CEST)

There is a bug with complex substitution in the stable branch; it the value starts with '$' as the very first character then it will (sometimes) switch back to simple substitution. This bug was fixed by eliminating simple substitution in the development branch. As a workaround, you can put a space as the first charatcer in the message, like this: message=" $foo_$b". --unsigned talk from Sapient

I have to admit that my previous claim (" Since Wesnoth 1.1.5, all simple substitution was eliminated in favor of complex substitution, which is more versatile.") was incorrect, because of the above description of how Wesnoth sometimes does "switch back to simple substitution". --Kernigh 22:00, 15 July 2007 (CEST)

Let me see if I got this right: In theory, all attributes that perform any substitution perform complex substitution, but due to a bug, complex substitution sometimes does simple substitution instead. We therefore tell users that only simple substitution is performed in the stable branch, because that is the only thing that is guaranteed to work. Meriton 22:17, 15 July 2007 (CEST)

Incorrect. I suggest you disregard Kernigh's statement, because it is misleading and false. There is still *lots* of simple substitution in the stable branch. (Including the bug with complex substitution sometimes reverting to simple substitution when the first character is '$'). If you are doing anything complex with WML you should be using the development branch because many improvements have been made. --Sapient

Ok, thanks for the clarification. --Meriton

Substitution mode of [set_variable]value= in stable branch

In the forums, governor claimed

{VARIABLE var1 $var2.xxxx} is valid.

which desugars to


I tested this in 1.2.5 with the code

{VARIABLE foo bar}
{VARIABLE test $foo}

Inspection of the save file revealed that "test" had been set to "bar".

What is the substitution mode for [set_variable]value= in the current stable branch? --Meriton

Answer: try it and see. If I remember correctly, [set_variable]value= performs simple substitution in the stable branch. Also, there was an effort primarily by Noyga to add complex substitution to lots of keys where he thought it would be useful. Unfortunately, he didn't document these changes as he went along. That's why the page is out of date. If you want to painstakingly retrace the evolution of variable substitution in the stable branch, be my guest, but I have moved on to improving the development branch. --Sapient

This page was last edited on 29 April 2011, at 02:03.