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?
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?