Multi-line WML
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.
Multi-line WML
Getting unexpected characters at line start errors because of this code, I want to avoid writing a large list in one line, so how do I write this over multiple lines?
Code: Select all
[set_variable]
name = DraftRedChoicesLeader1
rand = "Pikeman", "White Mage", "Red Mage", "Longbowman", "Javelineer", "Swordsman", "Knight", "Lancer", "Shock Trooper",
"Elvish Ranger","Dwarvish Steelclad"
[/set_variable]
Last edited by Pentarctagon on August 17th, 2021, 3:10 am, edited 1 time in total.
Reason: [c] to [code]
Reason: [c] to [code]
- beetlenaut
- Developer
- Posts: 2825
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: Multi-line WML
You probably have a carriage return after the "Shock Trooper", which is why you are getting an error. The easiest thing to do is just let the line extend, and let your text editor handle the word wrap. However, I did come up with a couple ways to do what you asked:
- You could use [set_variables] to fill an array and then use rand to choose an array index.
- You could set two temporary variables that are each chosen from half the list, then use rand to choose which of the two temp variables to use as the final value.
- You could use Lua for your coding. Its white-space formatting is less strict.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
- Spannerbag
- Posts: 535
- Joined: December 18th, 2016, 6:14 pm
- Location: Yes
Re: Multi-line WML
Hi,
You'd still have a long line of WML but it wouldn't look long.
Otherwise, you can shorten the line by omitting the double quotes and spaces; i.e. replace
which might shorten it enough? It should still work (but I haven't tried it!).
Otherwise I'd go with beetlenaut's first suggestion, you could even make it into a macro and re-use it elsewhere if need be...
Afaik there is no "line continuation" syntax in WML that allows code like yours above to span multiple lines (but then I do my coding in a basic text editor so what do I know?).
I'm curious as to why you dislike long lines? Are you having problems with them?
And apologies for the long line in this post
Cheers!
-- Spannerbag
Just my tuppence worth but if you're doing this to make your code easier to read, you could use one or more macros?Glen wrote: ↑August 17th, 2021, 2:46 am Getting unexpected characters at line start errors because of this code, I want to avoid writing a large list in one line, so how do I write this over multiple lines?Code: Select all
[set_variable] name = DraftRedChoicesLeader1 rand = "Pikeman", "White Mage", "Red Mage", "Longbowman", "Javelineer", "Swordsman", "Knight", "Lancer", "Shock Trooper", "Elvish Ranger","Dwarvish Steelclad" [/set_variable]
You'd still have a long line of WML but it wouldn't look long.
Otherwise, you can shorten the line by omitting the double quotes and spaces; i.e. replace
"Pikeman", "White Mage", "Red Mage", "Longbowman", "Javelineer", "Swordsman", "Knight", "Lancer", "Shock Trooper","Elvish Ranger","Dwarvish Steelclad"
withPikeman,White Mage,Red Mage,Longbowman,Javelineer,Swordsman,Knight,Lancer,Shock Trooper,Elvish Ranger,Dwarvish Steelclad
which might shorten it enough? It should still work (but I haven't tried it!).
Otherwise I'd go with beetlenaut's first suggestion, you could even make it into a macro and re-use it elsewhere if need be...
Afaik there is no "line continuation" syntax in WML that allows code like yours above to span multiple lines (but then I do my coding in a basic text editor so what do I know?).
I'm curious as to why you dislike long lines? Are you having problems with them?
And apologies for the long line in this post
Cheers!
-- Spannerbag
Re: Multi-line WML
key1 = "value1", "value2"
is the same as key1 = "value1,value2"
It is not special syntax the string pieces are just concatenated. (What is special syntax is: key1, key2 = "value1", "value2"
where actually two attributes are set in one line.)You can write the value as one big string that spans multiple lines but then those newlines are actually part of the string. You can also use the + operator to concatenate explicitely and if you put it at the end of the line the next line will be concatenated without the newline being part of the string.
Code: Select all
key1 = "value1," +
"value2"
"If gameplay requires it, they can be made to live on Venus." -- scott
- Spannerbag
- Posts: 535
- Joined: December 18th, 2016, 6:14 pm
- Location: Yes
Re: Multi-line WML
Wish I'd thought of that
-- Spannerbag
- Celtic_Minstrel
- Developer
- Posts: 2222
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Multi-line WML
Just a note, you can still use + on non-quoted strings as well, eg:
This collapses whitespace to a single space, so the final value of the key in that example is "value1 value2".
So for example, if you prefer to keep the commas outside the quotes as in your original example, this works:
Code: Select all
key1 = value +
value2
So for example, if you prefer to keep the commas outside the quotes as in your original example, this works:
Code: Select all
[set_variable]
name = DraftRedChoicesLeader1
rand = "Pikeman", "White Mage", "Red Mage", "Longbowman", "Javelineer", "Swordsman", "Knight", +
"Lancer", "Shock Trooper", "Elvish Ranger","Dwarvish Steelclad"
[/set_variable]