Create account / Log in

Bug or Feature: Inconsistent Beanshell property type parsing

Issues with the Vassal engine.

Moderators: uckelman, Tim M

Bug or Feature: Inconsistent Beanshell property type parsing

Postby marktb1961 » October 6th, 2020, 2:02 pm

This may not be new but I just spotted something odd in the way Beanshell is handling property types in the following situation...

Report Format (in a window GKC) includes an in-line calculation e.g. {"Result = " + gp+1 }
If gp=2, the output will be "Result= 21" ; gp is being treated as a string.

I discovered a workaround which forces numeric handling;-
define the Report Format as {"Result = " + (true ? gp+1 : 0) } ; now, if gp=2, the output will be "Result= 3"

I haven't tested but I assume this will be the same for GKC reports when the GKC is on a piece or for the Report Trait.

Mark
Platform used:
Vassal 3.4.10
MacOS Big Sur
iMac (27", mid-2020)
User avatar
marktb1961
 
Posts: 335
Joined: October 4th, 2018, 2:36 pm
Location: Liverpool, England

Re: Bug or Feature: Inconsistent Beanshell property type par

Postby Cattlesquat » October 6th, 2020, 4:31 pm

You might even be able to use just {"Result = " + (gp+1)}
User avatar
Cattlesquat
 
Posts: 947
Joined: December 2nd, 2019, 4:57 pm
Location: Baltimore, Maryland, USA

Re: Bug or Feature: Inconsistent Beanshell property type par

Postby Brent Easton » October 6th, 2020, 8:23 pm

Report Format (in a window GKC) includes an in-line calculation e.g. {"Result = " + gp+1 }
If gp=2, the output will be "Result= 21" ; gp is being treated as a string.


Yes, this is the expected behaviour. The operator + is evaluated from left to right, so gp is indeed being treated as a string as you are 'adding' it to a String. "Result = " + 2 evaluates to "Result = 2". Add on another 1 and you get "Result = 21". This is a natural consequence of the + operator doing double duty as numeric addition and string concatenation in an untyped language.

Brian's solution of {"Result = " + (gp+1)} is correct to force the gp+1 to be evaluated first.
User avatar
Brent Easton
 
Posts: 3226
Joined: December 21st, 2007, 3:06 am
Location: Berry, NSW, Australia

Re: Bug or Feature: Inconsistent Beanshell property type par

Postby marktb1961 » October 6th, 2020, 9:38 pm

Thanks both.
Platform used:
Vassal 3.4.10
MacOS Big Sur
iMac (27", mid-2020)
User avatar
marktb1961
 
Posts: 335
Joined: October 4th, 2018, 2:36 pm
Location: Liverpool, England


Return to Technical Support & Bugs

Who is online

Users browsing this forum: No registered users and 4 guests