This bug has actually been known for quite a long time. As you can tell, XML doesn't really like working with Lua in the same file. External scripts are a good work around, but there's no easy way to insert a less than sign (opening triangle bracket). There's just no way to differentiate the less than operation from an XML tag. Instead, consider reversing all conditionals to use the greater than sign exclusively.
For example, instead of:
if numberOfWorkers < 10 do
doSomething()
end
Use:
if ~(10 > numberOfWorkers) do -- If 10 is NOT greater than the number of workers
doSomething()
end
Of course, it is a bit annoying to be forced to write like this (especially since it's often more natural to write in the form of a "less than" equation, especially for loops that use a counter), so an external script is usually a better idea.
One alternative we could implement is to use CDATA tags on the content of XML tags (that is, the script portions). This means that the content of the tags (the "CDATA section") must be enclosed by
<![CDATA[ and
]]>. So the above code could end up looking something like:
<unitAttacked>
<![CDATA[
if numberOfWorkers < 10 do
doSomething()
end
]]>
</unitAttacked>
Those crazy characters explicitly mark the beginning and end of the XML tag content. Thus, we can assume that any "less than" signs inside the CDATA section must be part of the Lua code, since XML does not resume until the CDATA section is over. CDATA is commonly used to nest content in XML files. This would be, in my opinion, the best way to deal with this problem, but we'd have to make sure not to break existing scenarios, which will not contain the CDATA sections. Thus, the sections must be optional.
I imagine that any good XML parser should have built in support for CDATA sections. A quick google search seems to indicate that the
Xerces library does support CDATA (we still use Xerces, right?).
TL;DR: We should support CDATA sections in scenario XMLs (and encourage their use)