Difference between revisions of "Talk:SyntaxWML"

From The Battle for Wesnoth Wiki
(Empty Values)
(Empty Values)
Line 16: Line 16:
  
 
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.
 +
 
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 $metal_reserve$attacker_side|| is:
 +
 
1. Substitute in $attacker_side| to get eg $metal_reserve4|
 
1. Substitute in $attacker_side| to get eg $metal_reserve4|
 +
 
2. Substitute in $metal_reserve4| 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.
 +
 
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 $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
 
https://discord.com/channels/231976805987385345/442775044590927873/1078750511475470396

Revision as of 21:14, 24 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)


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