So, I have a module where I sum up a lot of different statistics in the stack viewer (makes for much easier counting…). But, one of these statistics (naturally the most important one) can have a value of 0.5.
I’ve tried a number of ideas to display this (some time ago), but none of them worked out.
Now, my understanding is that a ‘numeric’ variable in Vassal really only handles integers, so that explains much of the trouble. An easy way of getting out of situations like these is to just store the values, say, doubled, so that 1 is 2, and 0.5 is 1… and then divide it in half when you display it. But of course, you can’t do any math (that I know of) in the Stack Viewer controls. Summing is about all there is.
So, can there be anything added to the Stack Viewer to make some version of this work?
Or something like that? (You could add “” instead of “.0” if you want). I put the “” on the end to make sure Beanshell figured out you wanted a string. Possibly it would figure that out without it but I’m not sure.
Oh, heck no. I am not going to try and keep track of ship-equivalent #s in every hex of the board in a module that can have over a thousand (yes!) of counters active. I need to get back to looking at it just for the fleet boxes, but I have enough performance worries there (and sanity concerns).
Thats why there are /10’s in there. Also the Math.ceil stuff rounds up from anything over an integer. Without the Math.ceil the results displayed would be a non integer. Divide by 3, for ex, will give lots of non integers. I’ve used ((int) to convert back to integer. Note also the use of 5.0 and 3.0. These force the maths to calculate non integers. Using just 5 or 3 really mucks up the expected results.
This is well out of my knowledge, and not syntax I know other than seeing your example.
I can figure out the conversion in the general case. I can divide the SE by 2 (which, yes means internally setting it to double the real value…), but then the stack viewer just drops the non-integer portion. You talk about rounding it up, but I want to actually display it, because half points matter here.
Would there be a way to calculate a remainder and display that? ‘If odd number tack a “.5” on’?
I haven’t done this myself, but it looks like the stack viewer text takes Beanshell expressions, so what’s the problem? Surely you can just use a modulo and ? : expression to get what you want?
What this is supposed to do is output the text string of sum propertyName in your stack, which by default rounds down to the nearest integer, then get that number again but modulo 2, meaning divide by 2 and if there’s any remainder add the text string .5 to the end of the text output, or no remainder add no text.
Caveat that I’m far from an expert in this kind of thing, I literally just cobbled this together from the Vassal documentation, and I often make mistakes that need ironing out.
I agree that “You can use any introductory Java tutorial to learn more about the syntax of BeanShell Expressions” isn’t particularly helpful. What little I know is based on Googling and experimentation.
Now, I’m going to have to decide what I want to do about fighter ship equivalents (there’s some temporary changes that are user accessible, but not necessarily convenient…), change over various inventory windows, make sure everything lines up properly, refresh counters in a lot of save games…
I modified a part of my MOSV expression to remove the INT (Math.ceil…) part from the Number of CP / 3. Added 1 CP to the view. Now, instead of displaying 1, the MOSV shows 0.333333.
So, you have CPs, and it’s important to show what a fifth and a third of the total is? Particularly for the one-third bit, what significance does it have? That is, is a value of 1/3 actually important?
If so, then you’re probably going to want it to look more like my SE solution, where you do the if to display the final fraction. Since you seem to be using HTML mode, see if code like <sup>1</sup>⁄<sub>3</sub> will work for better display for you.