If you’re not a scripter and/or programmer, you might want to stop reading right here, or your head might explode.
I’ve been spending the last week or two revising the scripting stuff for V2. It has turned out to be a non-trivial task, but is nearing completion.
One of the more pleasant aspects is that I’m using the latest version of the compiler, which allows a lot more language features to be used than the old compiler (used for V1.x) did. Apart from some useful new language additions, some irritating bugs in the old compiler have been fixed (in particular Variants can now be used).
A Variant (for those who don’t know) is a variable type that can handle any (or most) data types. You can assign an integer, a double, a boolean, a string, or even an object to a variant and pass it into a method. So, for example, one can then replace
SaveIntegerValue(integer) SaveDoubleValue(double) SaveBooleanValue(boolean) SaveStringValue(string)
etc. with
SaveValue(variant)
which cuts down on a lot of code. I believe that the next version of the compiler (in beta) will even allow an array to be passed as a variant, simplifying stuff even more.
The Variant thing also means that the OLEObject stuff (much beloved of R.L-M) becomes a lot simpler (and will handle arrays, hopefully). It should also help simplify the plethora of methods associated with the EditParameters (customised dialog) feature (still to be looked at).
Another nice feature is the concept of shared methods in classes (sort of like “class methods” in C++). These are methods that are part of a class, but can be used independently of an instantiation of an object of that class. Apart from anything else, it’s a neat way of encapsulating global methods that are related to a particular class.
One improvement that I have done is most pleasing. You can now access multiple plan documents without having to jump through arcane coding hoops to get there. There’s a new class called APPlan that encapsulates a plan document, together with methods to get all open plans. There’s still the concept of the “current plan”, but now you can access things like Plan(3).Object(5).Observation(6), without fear, copy stuff from one plan to another, etc.
The biggest pain in the derriere was handling the new generalised user fields, that appear in objects, observations, sessions and resources. This required substantial coding effort.
The other big change has been removing the local/global observation dichotomy. This has resulted in a much nicer and simpler interface. A lot of code is being tossed and replaced by simpler (and hopefully more robust) code. There’s also support for sessions (APSession class).
A lot of existing stuff has been changed, but should not take more than a few minutes to fix in most existing scripts. Some stuff might take a bit longer, but will be all the better (and probably simpler) for the change.
I will be deprecating quite a lot of existing (V1.x) “global” methods, that have now become class or shared methods. Deprecation means “no longer supported, and will probably disappear in later versions of the app” – i.e. change your code to the approved way of doing things, or suffer the consequences in the future.
The name of the game here is generalised. V2 gives me the opportunity to refactor a lot of kludgy code to allow for easy (or easier) extension in the future. A fact that will (hopefully) be appreciated by the small handful of scripters out there.
This all does mean that V2 scripts will, in general, not be backwards compatible with V1.x. The script database for V2 will be separate from that of V1.x, but I suspect (i.e. hope) that most serious users will be upgrading.