I would also like this. While I can java number crunch using (float) to obtain a real number, the stack viewer refuses to add them using sum(propertyName). Works with Integers, just not real numbers.
Alternatively, can the Summary text above pieces area be made a beanshell expression area. With this ability, I could still use the existing sum(propertyName), but I would deliberately multiply that propertyName by 10 so the sum function still uses integers and then I divide the sum(propertyName) total by 10 within the stack viewer Summary text above pieces area to get what I want to be displayed.
sum should be OK. However, I keep getting error messages, basically, from the audit ability in prefs, the main issue is with the term. Paste from errorlog : Error=: Command not found: sum( int ). Same result for Sum(propertyName).
I restarted with the base term $sum(propertyName)$ works as per usual. Add the {} at either end the error occurs. Delete the $'s, error still occurs. I did note that when in this mode the property Name of tennav was reported as being 10, when it should have been 20. Thus using beanshell only looks at 1 counter not the 2+ that can exist.
I feel that there is a basic incompatibility with the $sum(propertyName)$ used by/in the summary text above pieces and its use within a beanshell expression.
While you are indeed correct that one can use beanshell expression in this area of the mouse over stack viewer, we cannot use a non beanshell expression that has been pre-defined within the Vassal code.
Drats, I say.
Ah! Right – the little local $sum(property)$ thing in the mouseover code is colliding with the Sum() that we built into Beanshell. I’ve just submitted a PR that will allow sumProperties(property) as a “synonym” that should work in the Beanshell versions of things. You can try a build of the “SumProperties” branch if you want when it comes up at vassalengine.org/builds, if you want to check it out. We’ll hopefully get it in the next 3.6 line we put out.
Installed 3.6.0 Snapshot 67f1f74 SumProperties. Following is result thus far:
2021-11-21 13:20:23,512 [20492-AWT-EventQueue-0] WARN VASSAL.tools.ErrorDialog - Source: {SumProperties(tennav)} Error: Expression evaluation error. See the errorlog for more details.
Expression Audit:
Source type=
Source name=
Source field=Summary text above pieces
Source Expression={SumProperties(tennav)}
tennav=20
Error=: Command not found: SumProperties( int )
2021-11-21 13:20:36,204 [20492-AWT-EventQueue-0] WARN VASSAL.tools.ErrorDialog - Source: {SumProperties(nav)} Error: Expression evaluation error. See the errorlog for more details.
Expression Audit:
Source type=
Source name=
Source field=Summary text above pieces
Source Expression={SumProperties(nav)}
nav=2
Error=: Command not found: SumProperties( int )
Could it be that it is not taking the 20 or 2 as an integer but text? That would be inconsistent though as the calculated property to obtain tennav is simply nav x 10. sumProperties does not work either.
Just tried the SumProduct as if it was just another name for the stack viewer $sum(property)$. SumProduct or sumProduct is just that. Something that works outside of any beanshell expression. sum(property) and sumProperty(property) will never work within a beanshell expression. What is needed is a beanshell expression that does the same job as either of these two terms. What that is I have no idea. I know java like the back of someone else’s hand.
Here is what I have now for the mouse over stack viewer for above the pieces:
{"" + “Ships: ATK:” + GetProperty(“sum(surf)”) + " #: " + GetProperty(“sum(noships)”) + " SUBs: ATK: " + GetProperty(“sum(subsurf)”) + " #: " + GetProperty(“sum(nosubs)”) + " All Naval: AA: " + GetProperty(“sum(aa)”) + " ASW: " + (GetProperty(“sum(asw)”)*1.0 + GetProperty(“sum(tennav)”)/10.0 + (Math.floor(GetProperty(“sum(nocps)”)/5.0))) + " ACFT: NAVAIR: " + GetProperty(“sum(tennav)”)/10.0 + " #NAVS: " + GetProperty(“sum(nonavacft)”) + " #Total: " + GetProperty(“sum(noacft)”) + " CPs: Total: " + GetProperty(“sum(nocps)”) + " CPs/5: " + ((int)(Math.ceil(GetProperty(“sum(nocps)”)/5.0))) + " CPs/3 : " + ((int)(Math.ceil(GetProperty(“sum(nocps)”)/3.0))) + " GND CF Total: " + GetProperty(“sum(groupcf)”) + " 3D10 Depletion: " + GetProperty(“sum(depletion3d10_Name)”)}
This works with beta 6, with one caveat that probably should be mentioned in the help area. Every propertyName used within the sum(propertyName) must have a value for every piece in the stack the mouse over viewer is active. The values can be 0, but there must be a value otherwise an error will occur. I thinnk it comes back to the basic, non beanshell, expression $sum(propertyName)$ which displays a sum of the property and adds an ? where there is no value for that property for a piece. When using a beanshell expression that ‘?’ mucks things up.
If Beanshell is working in this context, and the counters to be summed are in a stack, did you consider SumStack() ?
It amazes me that GetProperty(“sum(PropertyName)”) works, but from the above thread I understand it’s because there’s a second level of (non beanshell) evaluation being done on “sum()”. Is that right ?
Seems undesirable that sum() is tripped up by a non-numeric property value rather than just treating it as zero. I don’t think the beanshell functions do that.
SumStack does not work with multiple layers. When using $sum(propertyName)$ in the mouseover, if any piece in the mouseover stack does not have ‘propertyName’ defined then the mouseover top window adds a ? to the total displayed. So, when using a beanshell expression in the mouseover above display ie {beanshell}, the $sum(propertyName)$ does not work. You have to use the GetProperty() function for it to work. But if the “sum(propertyName)” returns a number and a ‘?’ then the beanshell expression fails with an error.