Escape commas
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.
Escape commas
I'm trying to make a character that yells random insults during attacks. I'm having trouble with strings that include a comma:
My problem is that the WML parser seems to use all of the commas as delimiters, so the above rand value appears to be a list of five strings instead of three. How do I escape the commas that are inside of the quotes?
I'm running Wesnoth 1.14
Code: Select all
[set_variable]
name=insult
rand="Have at you!","Come on then, you walking sack of meat!","Stand down, you fat-kidneyed knave!"
[/set_variable]
I'm running Wesnoth 1.14
Re: Escape commas
Maybe there's a way to escape them inline, I don't know about that, but otherwise you can just do this:
Code: Select all
{RANDOM 0..3}
[switch]
variable=random
[case]
value = 0
{VARIABLE insult ("Have at you!")}
[/case]
[case]
value = 1
{VARIABLE insult ("Come on then, you walking sack of meat!")}
[/case]
... same for 2 and 3
[/switch]
{CLEAR_VARIABLE random}
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
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
- Celtic_Minstrel
- Developer
- Posts: 2228
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Escape commas
There are a lot of places in the game where you can escape commas by enclosing the string in parentheses, like so:
Unfortunately, I don't think that works here… but it probably should, so I think I'll implement it for 1.15.11. By the way, you probably also want these strings to be translatable:
Or rather, since that doesn't actually work:
Code: Select all
rand=("Have at you!"),("Come on then, you walking sack of meat!"),("Stand down, you fat-kidneyed knave!")
Code: Select all
rand=(_"Have at you!"),(_"Come on then, you walking sack of meat!"),(_"Stand down, you fat-kidneyed knave!")
Code: Select all
{RANDOM 0..3}
[switch]
variable=random
[case]
value = 0
{VARIABLE insult (_"Have at you!")}
[/case]
[case]
value = 1
{VARIABLE insult (_"Come on then, you walking sack of meat!")}
[/case]
... same for 2 and 3
[/switch]
{CLEAR_VARIABLE random}
Re: Escape commas
It might be more efficient to put all the string texts in a [set_variables] then get a random index for one of them.
spares you the headache of a long [switch].
spares you the headache of a long [switch].