Question about (<change>) Expressions

Hello! I hope everyone is doing well.

I’m going to get straight into the nitty gritty. Is it possible to instantiate a new object within the change attribute expr?

The expression in question:

expr="$1.getCompulsions().add(new FollowCompulsion($1, $0))"

It looks legal to me, but I think something is going over my head, mainly due to how it yells at me that I need a comma between arguments and that it did “not supply a pattern or text generator or override format(TextBuilder)”

Anyways, thank you for your time and for a fun game.

Yes, it is possible for some things, but not using an expression like the one below. The expression parser doesn’t currently understand the token “new” - though I can see it would be useful. I may add it in time as I expand the expression parser functionality, but dynamically invoking constructors is more tricky than regular methods.

I think you can create things using factory classes using the expression parser, e.g. $0.add(/.factory("food").create("baconButty")), but it’s not something I do in the game - it works from the console though. There’s no factory for FollowCompulsion, in fact I find I’ve only used FollowCompulsion in unit tests so far.

I can’t tell if the “did not supply a pattern…” is just this error cascading up to the message generated for whatever you are trying to do, or is a separate problem.

It’s moaning about commas as it parses fine until the word “new”. As it doesn’t understand the token it is treating it as the name of an enum of some unknown type. It is then looking for a comma before the next arg to add, and “FollowCompulsion(…” doesn’t have one.

FYI, the changes to the parser in v0.43 can now handle “new” though it would need the full path to the class as there are no imports.