Using the ^ character in strings

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
WedgeR8
Posts: 7
Joined: December 27th, 2018, 11:09 am

Using the ^ character in strings

Post by WedgeR8 »

I didn't find anything regarding this in the wiki so I'm asking here

For some reason every time I use ^ in a message string it deletes huge parts of the string, for example, if I write this

Code: Select all

[message]
    speaker=my_unit
    message= _ "Hello ^World"
[/message]
the unit just says "World", how can I fix this?
User avatar
octalot
General Code Maintainer
Posts: 783
Joined: July 17th, 2010, 7:40 pm
Location: Austria

Re: Using the ^ character in strings

Post by octalot »

Documentation and the explanation about this is on the GettextForWesnothDevelopers page

In 1.15, everything up until the first ^ will be removed, you can include a literal ^ by doing "prefix^Hello ^World".

In 1.14, everything up until the last ^ is removed, there isn't a workaround for that (as far as I can remember).
User avatar
WhiteWolf
Forum Moderator
Posts: 769
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: Using the ^ character in strings

Post by WhiteWolf »

There's this simple workaround that seems to work fine in 1.14 too:

Code: Select all

{VARIABLE helper "^"}
[message]
    speaker=my_unit
    message= _ "Hello $helper|World"
[/message]
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
User avatar
Celtic_Minstrel
Developer
Posts: 2166
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Using the ^ character in strings

Post by Celtic_Minstrel »

You could also just add an extra ^ at the start of your string.

Code: Select all

[message]
    speaker=my_unit
    message= _ "^Hello ^World"
[/message]
That should show "Hello ^World". I guess maybe it doesn't work in 1.14 though.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
Elvish_Hunter
Posts: 1575
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: Using the ^ character in strings

Post by Elvish_Hunter »

You can always try escaping it just like a HTML entity. The following code seems to work on the 1.15 series:

Code: Select all

        [message]
            speaker=narrator
            caption= _ "Caret test"
            message= _ "This should be a literal caret: ^."
        [/message]
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
User avatar
Celtic_Minstrel
Developer
Posts: 2166
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Using the ^ character in strings

Post by Celtic_Minstrel »

Just keep in mind that that's not guaranteed to work everywhere - it'll only work in places that Pango markup is enabled.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Post Reply