PDA

View Full Version : LUA Less Than vs XML Tag



Natai
March 8th, 2008, 19:25
I am new to xml and LUA, and I am having a problem with xml treating the < (less than) in a script like a tag.
In the code below I entered if difference < 0 then difference = 0 to avoid problems with negatives. However, xml keeps trying to treat the < like the beginning of a tag and causing an error.

<script>
function onSourceUpdate()
local maxcarry = sources["derived.carryingcap.carry"].getValue();
local currentweight = sources["derived.carryingcap.current"].getValue();
local difference = currentweight - maxcarry;
if difference < 0 then difference = 0 end
setValue(math.ceil(difference / 25));
end
</script>
I managed to get around the problem by avoiding the < in favor of a combination of not and >= in the code below:

<script>
function onSourceUpdate()
local maxcarry = sources["derived.carryingcap.carry"].getValue();
local currentweight = sources["derived.carryingcap.current"].getValue();
local difference = currentweight - maxcarry;
if not (difference >= 0) then difference = 0 end
setValue(math.ceil(difference / 25));
end
</script>
So I got it to work, but it seems like there must be an easier way. I thought xml should avoid trying to use anything between <script> and </script>. Any suggestions?

sloejack
March 8th, 2008, 20:46
looking through some of the stuff in the default d20, I see cases where they used &lt; in place of the < - I would assume this would work then since they used it.

joshuha
March 8th, 2008, 20:57
Yeah its mentioned under here:
https://fantasygrounds.com/modguide/scripting.xcp

Basically &lt and &gt are needed if you are inlining script in XML.

Oberoten
March 8th, 2008, 22:18
That or simply changing the place of the arguments.

A < B = B > A after all.

Foen
March 9th, 2008, 15:45
It is best to use the escape sequences &lt; and &gt; (remember the semi-colons at the end), rather than relying on > being a safe symbol (it isn't defined as safe).

Stuart

sloejack
March 10th, 2008, 04:04
It is best to use the escape sequences &lt; and &gt; (remember the semi-colons at the end), rather than relying on > being a safe symbol (it isn't defined as safe).


Just to echo and add to this, this is especially true if you use something like the XML checker in notepad++ where the < and > could be percieved as an attempt to create a tag depending on your coding/writing style.