Dynamic Property with a string added not evaluating

I have a situation with a string that is not behaving as I would like it to. I don’t know what I am missing but I think it should work.

I have a Dynamic Property that figures out the firepower for a unit and it works just fine.

(origSPs - SPLoss) < 2 ? (Math.round((float)FVOriginal / 2)) : FVOriginal

If it finds that the SP is one or lower it gets half the fire value but if there are 2 or more SP it gets the full fire value.

I want to add a string to that so it would look like:

(origSPs - SPLoss) < 2 ? (Math.round((float)FVOriginal / 2)) “Range 3” : FVOriginal “Range 3”

The result would look like 4 Range 3 or 2 Range 3 depending on the SP.

The result is blank.

I jnow this is my not knowing strings well here but if anyone has some help, that would be great.

You need to use the string concatenation operator + between the number and the string. Concatenating something of type T, that can be turned into a string via the static member function T.toString - say an integer - with a String automatically promotes the non-string argument to String. That is, your expression should be

(origSPs - SPLoss) < 2 ? (Math.round((float)FVOriginal / 2)) + " Range 3" : FVOriginal + " Range 3"

(note the extra leading spaces).

If you want to be explicit, you can do

(origSPs - SPLoss) < 2 ? Integer.toString(Math.round((float)FVOriginal / 2)) + " Range 3" : Integer.toString(FVOriginal) + " Range 3"

Again, you can test this with the standalone BeanShell interpreter. Put the lines

origSPs    = 10;
FVOriginal = 5;

SPLoss     = 0;
FV = (origSPs - SPLoss) < 2 ? (Math.round((float)FVOriginal / 2)) : FVOriginal;
print("SPLoss="+SPLoss+" FV="+FV);

SPLoss = 1;
FV = (origSPs - SPLoss) < 2 ? (Math.round((float)FVOriginal / 2)) : FVOriginal;
print("SPLoss="+SPLoss+" FV="+FV);

SPLoss = 9;
FV = (origSPs - SPLoss) < 2 ? (Math.round((float)FVOriginal / 2)) : FVOriginal;
print("SPLoss="+SPLoss+" FV="+FV);


SPLoss = 0;
FVR = (origSPs - SPLoss) < 2 ? (Math.round((float)FVOriginal / 2)) + " Range 3" : FVOriginal + " Range 3";
print("SPLoss="+SPLoss+" FVR="+FVR);

FVR = (origSPs - SPLoss) < 2 ? Integer.toString(Math.round((float)FVOriginal / 2)) + " Range 3" : Integer.toString(FVOriginal) + " Range 3";
print("SPLoss="+SPLoss+" FVR="+FVR);

in a file - say test.bs, and run

$ bsh test.bs

Yours,
Christian

Christian. That did it. Used the + and the leading space which seemed most explicit.

Appreciate your time!