Is string concatenation broken?

The place to post your WML questions and answers.

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.
Post Reply
User avatar
beetlenaut
Developer
Posts: 2812
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Is string concatenation broken?

Post by beetlenaut »

Am I doing something wrong, or has this been broken for a while?

Code: Select all

[set_variable]
    name=var
    value="foo"
[/set_variable]

{DEBUG_MSG ($var)}                  #1
{DEBUG_MSG ("var=" + $var )}        #2
{DEBUG_MSG ($var + "bar")}          #3
{DEBUG_MSG ("var=" + $var + "bar")} #4
Both #1 and #2 work as I expected. They show foo and var=foo. But, #3 shows nothing, and #4 returns only var=. Putting quotes around $var doesn't make any difference. I can use formulaWML to concatenate strings, so I have a workaround, but didn't this use to work? (I tested this code in 1.14.5 and 1.14.4 and got the same results.)
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
gfgtdf
Developer
Posts: 1431
Joined: February 10th, 2013, 2:25 pm

Re: Is string concatenation broken?

Post by gfgtdf »

thius is the expected behaviour, what you have to understand is that string concatination happens at preproceccing/parsing time (when macors are expanded) while variable subsitution happens at runtime, so procroceccing/parsing will concationate your #3 to {DEBUG_MSG ("$varbar")} and then at runtime the variable varbar will not be found. To workaround this issue you ahve to explciitly end your vairlbaes with a |
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
beetlenaut
Developer
Posts: 2812
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Is string concatenation broken?

Post by beetlenaut »

That makes sense, thanks. I don't remember ever adding vertical bars before, but it does work that way.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
Post Reply