a bug? spaces are discarded / added (BfW 1.10)
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.
-
- Posts: 876
- Joined: November 28th, 2008, 6:18 pm
a bug? spaces are discarded / added (BfW 1.10)
With BfW 1.10 this code
shows
The code worked correctly with BfW 1.8.
Code: Select all
{VARIABLE maximal_value 6}
[message]
speaker=narrator
message=Amount: up to $maximal_value
[/message]
It looks ':' and '$' cause the problem.Amount:up to6
The code worked correctly with BfW 1.8.
Last edited by SlowThinker on March 27th, 2012, 9:55 am, edited 1 time in total.
I work on Conquest Minus • I use DFoolWide, Retro Terrain Package and the add-on 'High Contrast Water'
I moved to Nosebane's corner (Doc Paterson's signature); I am spending my time there, so PM me if I don't answer your post in forums
I moved to Nosebane's corner (Doc Paterson's signature); I am spending my time there, so PM me if I don't answer your post in forums
Re: a bug? [message] discards some spaces (BfW 1.10)
Try
message=_"Amount: up to $maximal_value"
.-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: a bug? [message] discards some spaces (BfW 1.10)
What 8680 says.
The change in behavior of the engine is probably the same as the originally reported issue here: http://gna.org/bugs/?func=detailitem&it ... 92#options
(The decision was to won't fix it due to being negligible.)
The change in behavior of the engine is probably the same as the originally reported issue here: http://gna.org/bugs/?func=detailitem&it ... 92#options
(The decision was to won't fix it due to being negligible.)
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
-
- Posts: 876
- Joined: November 28th, 2008, 6:18 pm
Re: a bug? [message] discards some spaces (BfW 1.10)
Hm ... is the link correct?Anonymissimus wrote:The change in behavior of the engine is probably the same as the originally reported issue here: http://gna.org/bugs/?func=detailitem&it ... 92#options
My view is very different. I believe any programming language should avoid exceptions and be as compact as possible ... and not only because of WML newbies.Anonymissimus wrote:The decision was to won't fix it due to being negligible.
------------------------------------
I ran some tests (1.10.1) and my observation is a bit different from the 8680's hint. The following statements may be true with BfW 1.10:
- The translation tag is not essential, only the quotes are essential
- any attribute whose value is not in the quoted form
key="value"
may be damaged - $text "brings (invisible) quotes included", and so
key=$var
is safe
the test
**********************************************wiki wrote:a quoted value is a value surrounded by quotes. Note for single-line values this is completely unnecessary
Edit:
**********************************************
It looks the problem above may be solved if one puts all values in parenthesis, but it doesn't work in the following situation:
Spaces besides special characters are lost from parameters of macros:
Code: Select all
#define VARIABLE_MACRO VAR TEXT
[set_variable]
name="{VAR}"
value="{TEXT}"
[/set_variable]
#enddef
{VARIABLE_MACRO var1 "- some text (content of parentheses)" } # it eats spaces: '-some text(content of parentheses)'
an observation, not so important
--------------------------------------------------
Another change between the syntax of 1.8 and 1.10 is:
'+' adds a space
Code: Select all
{VARIABLE my_var wes+noth} # 1.8: 'wesnoth' 1.10: 'wes noth'
I work on Conquest Minus • I use DFoolWide, Retro Terrain Package and the add-on 'High Contrast Water'
I moved to Nosebane's corner (Doc Paterson's signature); I am spending my time there, so PM me if I don't answer your post in forums
I moved to Nosebane's corner (Doc Paterson's signature); I am spending my time there, so PM me if I don't answer your post in forums
Re: a bug? [message] discards some spaces (BfW 1.10)
Essential, no, but any string to be displayed to the user should be marked translatable.SlowThinker wrote:I ran some tests (1.10.1) and my observation is a bit different from the 8680's hint. The following statements may be true with BfW 1.10:
- The translation tag is not essential, only the quotes are essential
Wouldn't that expand to this?SlowThinker wrote:Code: Select all
#define VARIABLE_MACRO VAR TEXT [set_variable] name="{VAR}" value="{TEXT}" [/set_variable] #enddef {VARIABLE_MACRO var1 "- some text (content of parentheses)" } # it eats spaces: '-some text(content of parentheses)'
Code: Select all
[set_variable]
name="var1"
value=""- some text (content of parentheses)""
[/set_variable]
-
- Posts: 876
- Joined: November 28th, 2008, 6:18 pm
Re: a bug? [message] discards some spaces (BfW 1.10)
(edit: "Wouldn't that expand to this?" ... the question is answered further)
next code works well:
-----------------------------------------------------
Now how to avoid this bug by following a simple rule? (like "always use quoted values" in case no macros are used)
A solution would be to use () in place of "":
the problem is arguments couldn't use parentheses inside:
next code works well:
Code: Select all
#define VARIABLE_MACRO2 VAR TEXT
[set_variable]
name="{VAR}"
value={TEXT}
[/set_variable]
#enddef
{VARIABLE_MACRO2 var1 "- some text (content of parentheses)" }
Now how to avoid this bug by following a simple rule? (like "always use quoted values" in case no macros are used)
A solution would be to use () in place of "":
Code: Select all
{VARIABLE_MACRO var1 (- some text - content of parentheses) # this works}
Code: Select all
{VARIABLE_MACRO var1 (- some text (content of parentheses)) # error: preprocessor symbol 'VARIABLE_MACRO' expects 2 arguments, but has 3 arguments}
Last edited by SlowThinker on March 31st, 2012, 1:39 pm, edited 2 times in total.
I work on Conquest Minus • I use DFoolWide, Retro Terrain Package and the add-on 'High Contrast Water'
I moved to Nosebane's corner (Doc Paterson's signature); I am spending my time there, so PM me if I don't answer your post in forums
I moved to Nosebane's corner (Doc Paterson's signature); I am spending my time there, so PM me if I don't answer your post in forums
Re: a bug? [message] discards some spaces (BfW 1.10)
Don't quote the arguments in the macro definition.SlowThinker wrote:Now how to avoid this bug by following a simple rule?
-
- Posts: 876
- Joined: November 28th, 2008, 6:18 pm
Re: a bug? [message] discards some spaces (BfW 1.10)
I didn't quote the argument, but all the value.
In general the value must be quoted if one wants to avoid the bug.
In general the value must be quoted if one wants to avoid the bug.
Re: a bug? spaces are discarded / added (BfW 1.10)
Code: Select all
## Macro definition.
#define SET_VAR NAME VALUE
[set_variable]
name={NAME} ## Don't quote.
value={VALUE}
[/set_variable]
#enddef
## Macro use. Arguments quoted where necessary.
{SET_VAR var1 blah}
{SET_VAR var2 "blah blah blah"}
{SET_VAR var3 _"blah blah"}
-
- Posts: 876
- Joined: November 28th, 2008, 6:18 pm
Re: a bug? spaces are discarded / added (BfW 1.10)
Your method won't work here:
But surprisingly for me, next method works (at least in my tests):
the method is:
I was surprised that the code above worked well. I expected after the macro expansion the double-quotes would work like here:
Code: Select all
#define VARIABLE_MACRO VAR ARG1 ARG2
[set_variable]
name={VAR}
value={ARG1} - {ARG2}
[/set_variable]
#enddef
{VARIABLE_MACRO var01 "( 1 )" "( 2 )" } # spaces around the hyphen are discarded: '( 1 )-( 2 )'
Code: Select all
#define VARIABLE_MACRO VAR ARG1 ARG2
[set_variable]
name={VAR}
value={ARG1}" - "{ARG2}
[/set_variable]
#enddef
{VARIABLE_MACRO var02 "( 1 )" "( 2 )" } # works well: '( 1 ) - ( 2 )'
- in the macro definitions, quote values, but skip all references to arguments
- in the macro "calls", quote arguments
I was surprised that the code above worked well. I expected after the macro expansion the double-quotes would work like here:
Code: Select all
[set_variable]
name=var03
value="( 1 )"" - ""( 2 )" # works different: '( 1 )" - "( 2 )'
[/set_variable]
-
- Posts: 876
- Joined: November 28th, 2008, 6:18 pm
Re: a bug? spaces are discarded / added (BfW 1.10)
I tried to verify the previous hypothesis...
This is really confusing, now I see no logic there ...
(still the "method" in my previous post might work)
... so I tested it (I created a save), and the answer is "no". It expands to8680 wrote:Wouldn't that expand to this?SlowThinker wrote:Code: Select all
#define VARIABLE_MACRO VAR TEXT [set_variable] name="{VAR}" value="{TEXT}" [/set_variable] #enddef {VARIABLE_MACRO var1 "- some text (content of parentheses)" } # it eats spaces: '-some text(content of parentheses)'
Code: Select all
[set_variable] name="var1" value=""- some text (content of parentheses)"" [/set_variable]
Code: Select all
[set_variable]
name="var1"
value="-some text(content of parentheses)"
[/set_variable]
(still the "method" in my previous post might work)
I work on Conquest Minus • I use DFoolWide, Retro Terrain Package and the add-on 'High Contrast Water'
I moved to Nosebane's corner (Doc Paterson's signature); I am spending my time there, so PM me if I don't answer your post in forums
I moved to Nosebane's corner (Doc Paterson's signature); I am spending my time there, so PM me if I don't answer your post in forums
Re: a bug? spaces are discarded / added (BfW 1.10)
Maybe spaces are collapsed, then quotes are collapsed?
-
- Posts: 876
- Joined: November 28th, 2008, 6:18 pm
Re: a bug? spaces are discarded / added (BfW 1.10)
Anyway the behaviour (spaces are / aren't discarded) depends on the position the argument is inserted to.
and I start to think studying effects of a bug is not very expedient ...
and I start to think studying effects of a bug is not very expedient ...