Log in

View Full Version : Scripting - Using < and > operators



MadBeardMan
November 22nd, 2015, 14:02
Afternoon Folks,

Been working on the scripting required for working out the MOD values within Traveller.

However I've spent that last hour or more (time flies when you're coding) hitting a brick wall.

Seems;


if nMyValue == 0 then
nMyModValue = -3;
elseif nMyValue <=2 then
nMyModValue = -2;
elseif nMyValue <=4 then
nMyModValue = -1;
end

Throws an error upon loading the ruleset.

However I do have it working using a long winded method


function onSourceUpdate()

local nValue = calculateSources();
local nModValue = 0;

if nValue == 0 then
nModValue = -3;
elseif nValue == 1 then
nModValue = -2;
elseif nValue == 2 then
nModValue = -2;
else
nModValue = 0;
end

However I've got the values 0-15 to check so that's a lot of code for something I should be able to (hopefully) say x < y.

Cheers
Colin

Andraax
November 22nd, 2015, 16:24
Is your code in an XML file? If so, you need to replace "<" with "&lt;" and ">" with "&gt;".

Valarian
November 22nd, 2015, 21:57
In Lua, you should be able to use the alternative operators: gt, lt, ge, le. These replace >, <, >= and <=. This avoids conflict with the XML.

MadBeardMan
November 23rd, 2015, 09:33
Morning Folks,

Oddness, I thought I replied to this thread last night.

Got it working, using the &lt; etc as this is within the character sheet XML main.

Now I'm going to experiment with it, as I hate having the exact same code copied for each ability so I'll see if I can move it to it's own script file (then comes the fun of passing arguments).

Cheers though, got it working.

Colin