Difference between revisions of "Talk:SyntaxWML"

From The Battle for Wesnoth Wiki
(Empty Values)
(Properly attribute that quote to me)
Line 14: Line 14:
 
[[User:Meriton|Meriton]] 15:49, 15 July 2007 (CEST)
 
[[User:Meriton|Meriton]] 15:49, 15 July 2007 (CEST)
  
 +
Noted by Celtic Minstrel on IRC:
 +
<blockquote>
 +
There are two variables, so two pipes should be fine.
  
 
In fact, as long as there's whitespace after it, no pipes would also be fine.
 
In fact, as long as there's whitespace after it, no pipes would also be fine.
Line 19: Line 22:
 
The pipe is an optional part of the syntax used to disambiguate where the variable name ends if it's not otherwise clear.
 
The pipe is an optional part of the syntax used to disambiguate where the variable name ends if it's not otherwise clear.
  
What should happen when the game processes $metal_reserve$attacker_side|| is:
+
What should happen when the game processes <code>$metal_reserve$attacker_side||</code> is:
  
1. Substitute in $attacker_side| to get eg $metal_reserve4|
+
# Substitute in <code>$attacker_side|</code> to get eg <code>$metal_reserve4|</code>
 
+
# Substitute in <code>$metal_reserve4|</code> to get 12 or whatever.
2. Substitute in $metal_reserve4| to get 12 or whatever.
 
  
 
Substitutions always happen from right to left.
 
Substitutions always happen from right to left.
Line 29: Line 31:
 
And if there's a pipe, the substitution removes it.
 
And if there's a pipe, the substitution removes it.
  
So having only 1 pipe would mean that $metal_reserve|stuff tries to read the variable metal_reserve4stuff instead of metal_reserve4 which is likely not the intention. Thus, always better to match the number of pipes to the number of $'s in this type of situation, unless you know that's not what you want.
+
So having only 1 pipe would mean that <code>metal_reserve|stuff</code> tries to read the variable metal_reserve4stuff instead of metal_reserve4 which is likely not the intention. Thus, always better to match the number of pipes to the number of $'s in this type of situation, unless you know that's not what you want
 +
</blockquote>
  
 
https://discord.com/channels/231976805987385345/442775044590927873/1078750511475470396
 
https://discord.com/channels/231976805987385345/442775044590927873/1078750511475470396

Revision as of 14:18, 26 February 2023

Empty Values

The workaround I posted was helpful to check whether a variable is initialized:

[variable]
    name=to_be_tested
    equals=$empty
[/variable]

(tested with wesnoth 1.2.5)

Interesting it doesn't work with [set_variable]format=.

Meriton 15:49, 15 July 2007 (CEST)

Noted by Celtic Minstrel on IRC:

There are two variables, so two pipes should be fine.

In fact, as long as there's whitespace after it, no pipes would also be fine.

The pipe is an optional part of the syntax used to disambiguate where the variable name ends if it's not otherwise clear.

What should happen when the game processes $metal_reserve$attacker_side|| is:

  1. Substitute in $attacker_side| to get eg $metal_reserve4|
  2. Substitute in $metal_reserve4| to get 12 or whatever.

Substitutions always happen from right to left.

And if there's a pipe, the substitution removes it.

So having only 1 pipe would mean that metal_reserve|stuff tries to read the variable metal_reserve4stuff instead of metal_reserve4 which is likely not the intention. Thus, always better to match the number of pipes to the number of $'s in this type of situation, unless you know that's not what you want

https://discord.com/channels/231976805987385345/442775044590927873/1078750511475470396