Strange error messages

Error log extract:
2021-11-25 22:30:45,058 [25640-AWT-EventQueue-0] WARN - Piece: CHCOM C1 La11 Trait: Calculated Property - presentzone - getweather Source: {GetProperty(“CurrentZone”).substring(0,6)} Error: Expression evaluation error. See the errorlog for more details.
Expression Audit:
Source type=Piece Trait
Source name=Piece: CHCOM C1 La11
Source description=Trait: Calculated Property - presentzone - getweather
Source field=Expression
Source Expression={GetProperty(“CurrentZone”).substring(0,6)}
Error=: Method Invocation substring
This comes from three CPs that applies to all aircraft and CV aircraft and reside within their prototypes. Essentially the CPs determine what a zone’s weather is to modify their NAV factors accordingly (full in fine, half in rain/snow, 0 in storm/blizzard). See attached pics.

I thought I might be able to obviate this error by defining a GP called CurrentZone=ntempa as an initial value. But no it does not seem to be working that way.
Be interested in any thoughts.

This expression is the same as CurrentZone.substring(0,6) is it not?
I can’t recall if GetProperty().function() works, but I’m guessing it does.

If you meant to get the value of a property named after the Zone name, then you would use : {GetProperty(CurrentZone).substring(0,6)}

I do recall an issue if the string is not a long as the substring() specifies.

Do you even need to use the CurrentZone name? Have you considered defining a Global Property within the zone that gives you the zone’s weather directly?

You have weatherzone set to GetProperty(presentzone) which takes the value of the presentzone property, and attempts to use that as the name of a property, of which it is then attempting to get the value of.

So in other words I think you probably want GetProperty("presentzone") or its equivalent which is to just type presentzone by itself into the Expression line for the CP

{GetProperty(CurrentZone).substring)0,6)} returns nothing. The way these particular CPs work is that the 1st one uses the name of a zone (say ntempaland) and the result is ‘ntempa’ (North Temperate). The 2nd CP then uses the ntempa to return which zone highlighter is active in that zone, fine (default GP), rain, snow, storm or blizzard. The process works quite well and I have never had any issues with it before now.
As to your last para, how can I do that?

Changing that CP to GetProperty(“presentzone”) just returns the contents of presenzone - that is if presentzone from the 1st CP was ntempa, then the result is ntempa. Omitting the “” gives the name of the current active zone highlighter.

As Mark mentioned, substring(x,y) will error if the string has less than y characters, which could occur if the piece isn’t currently in a named Zone. Try CurrentZone.length() < 6 ? "defaultzone" : CurrentZone.substring(0,6) (where “defaultzone” is the first 6 characters of an actual zone).

This will prevent substring from trying to run on a string of less than 6 characters, and also help ensure that presentzone always has a valid value so the weatherzone calculation doesn’t error, either.

Excellent suggestion. Go to the top of the class. Much nicer expression as well. :grinning:
Thank you all very much.

1 Like